From 23e9a607353a21e5094a0165fafc8c92d36fe899 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 28 Jun 2017 15:41:19 +0100 Subject: [PATCH 01/42] WIP --- .meteor/packages | 1 + .meteor/versions | 1 + .../.npm/package/.gitignore | 1 + .../rocketchat-graphql/.npm/package/README | 7 + .../.npm/package/npm-shrinkwrap.json | 334 ++++++++++++++++++ packages/rocketchat-graphql/package.js | 27 ++ packages/rocketchat-graphql/server/api.js | 36 ++ .../server/helpers/findChannelByIdAndUser.js | 8 + .../server/helpers/property.js | 3 + packages/rocketchat-graphql/server/schema.js | 179 ++++++++++ 10 files changed, 597 insertions(+) create mode 100644 packages/rocketchat-graphql/.npm/package/.gitignore create mode 100644 packages/rocketchat-graphql/.npm/package/README create mode 100644 packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json create mode 100644 packages/rocketchat-graphql/package.js create mode 100644 packages/rocketchat-graphql/server/api.js create mode 100644 packages/rocketchat-graphql/server/helpers/findChannelByIdAndUser.js create mode 100644 packages/rocketchat-graphql/server/helpers/property.js create mode 100644 packages/rocketchat-graphql/server/schema.js diff --git a/.meteor/packages b/.meteor/packages index 1baeab932dec..53fb9389b819 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -63,6 +63,7 @@ rocketchat:file-upload rocketchat:github-enterprise rocketchat:gitlab rocketchat:google-vision +rocketchat:graphql rocketchat:highlight-words rocketchat:iframe-login rocketchat:importer diff --git a/.meteor/versions b/.meteor/versions index 56584e33d724..5ceb7cee121a 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -151,6 +151,7 @@ rocketchat:file-upload@0.0.1 rocketchat:github-enterprise@0.0.1 rocketchat:gitlab@0.0.1 rocketchat:google-vision@0.0.1 +rocketchat:graphql@0.0.1 rocketchat:highlight-words@0.0.1 rocketchat:i18n@0.0.1 rocketchat:iframe-login@1.0.0 diff --git a/packages/rocketchat-graphql/.npm/package/.gitignore b/packages/rocketchat-graphql/.npm/package/.gitignore new file mode 100644 index 000000000000..3c3629e647f5 --- /dev/null +++ b/packages/rocketchat-graphql/.npm/package/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/packages/rocketchat-graphql/.npm/package/README b/packages/rocketchat-graphql/.npm/package/README new file mode 100644 index 000000000000..3d492553a438 --- /dev/null +++ b/packages/rocketchat-graphql/.npm/package/README @@ -0,0 +1,7 @@ +This directory and the files immediately inside it are automatically generated +when you change this package's NPM dependencies. Commit the files in this +directory (npm-shrinkwrap.json, .gitignore, and this README) to source control +so that others run the same versions of sub-dependencies. + +You should NOT check in the node_modules directory that Meteor automatically +creates; if you are using git, the .gitignore file tells git to ignore it. diff --git a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json new file mode 100644 index 000000000000..99bd39438b7f --- /dev/null +++ b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json @@ -0,0 +1,334 @@ +{ + "dependencies": { + "accepts": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.3.tgz", + "from": "accepts@>=1.3.3 <1.4.0" + }, + "apollo-client": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/apollo-client/-/apollo-client-1.6.0.tgz", + "from": "apollo-client@1.6.0" + }, + "array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "from": "array-flatten@1.1.1" + }, + "body-parser": { + "version": "1.17.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.17.2.tgz", + "from": "body-parser@1.17.2" + }, + "bytes": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz", + "from": "bytes@2.4.0" + }, + "content-disposition": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", + "from": "content-disposition@0.5.2" + }, + "content-type": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.2.tgz", + "from": "content-type@>=1.0.2 <1.1.0" + }, + "cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "from": "cookie@0.3.1" + }, + "cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "from": "cookie-signature@1.0.6" + }, + "cors": { + "version": "2.8.3", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.3.tgz", + "from": "cors@2.8.3" + }, + "debug": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.7.tgz", + "from": "debug@2.6.7" + }, + "depd": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.0.tgz", + "from": "depd@>=1.1.0 <1.2.0" + }, + "deprecated-decorator": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz", + "from": "deprecated-decorator@>=0.1.6 <0.2.0" + }, + "destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "from": "destroy@>=1.0.4 <1.1.0" + }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "from": "ee-first@1.1.1" + }, + "encodeurl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz", + "from": "encodeurl@>=1.0.1 <1.1.0" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "from": "escape-html@>=1.0.3 <1.1.0" + }, + "etag": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.0.tgz", + "from": "etag@>=1.8.0 <1.9.0" + }, + "express": { + "version": "4.15.3", + "resolved": "https://registry.npmjs.org/express/-/express-4.15.3.tgz", + "from": "express@4.15.3" + }, + "finalhandler": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.3.tgz", + "from": "finalhandler@>=1.0.3 <1.1.0" + }, + "forwarded": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.0.tgz", + "from": "forwarded@>=0.1.0 <0.2.0" + }, + "fresh": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.0.tgz", + "from": "fresh@0.5.0" + }, + "graphql": { + "version": "0.10.3", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-0.10.3.tgz", + "from": "graphql@0.10.3" + }, + "graphql-anywhere": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/graphql-anywhere/-/graphql-anywhere-3.1.0.tgz", + "from": "graphql-anywhere@>=3.0.1 <4.0.0" + }, + "graphql-server-core": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/graphql-server-core/-/graphql-server-core-0.9.0.tgz", + "from": "graphql-server-core@>=0.9.0 <0.10.0" + }, + "graphql-server-express": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/graphql-server-express/-/graphql-server-express-0.9.0.tgz", + "from": "graphql-server-express@0.9.0" + }, + "graphql-server-module-graphiql": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/graphql-server-module-graphiql/-/graphql-server-module-graphiql-0.9.0.tgz", + "from": "graphql-server-module-graphiql@>=0.9.0 <0.10.0" + }, + "graphql-tag": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.4.2.tgz", + "from": "graphql-tag@>=2.0.0 <3.0.0" + }, + "graphql-tools": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-1.0.0.tgz", + "from": "graphql-tools@1.0.0" + }, + "http-errors": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.1.tgz", + "from": "http-errors@>=1.6.1 <1.7.0" + }, + "iconv-lite": { + "version": "0.4.15", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.15.tgz", + "from": "iconv-lite@0.4.15" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "from": "inherits@2.0.3" + }, + "ipaddr.js": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.3.0.tgz", + "from": "ipaddr.js@1.3.0" + }, + "iterall": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.1.1.tgz", + "from": "iterall@>=1.1.0 <2.0.0" + }, + "js-tokens": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.1.tgz", + "from": "js-tokens@>=3.0.0 <4.0.0" + }, + "lodash": { + "version": "4.17.4", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", + "from": "lodash@>=4.2.1 <5.0.0" + }, + "lodash-es": { + "version": "4.17.4", + "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.4.tgz", + "from": "lodash-es@>=4.2.1 <5.0.0" + }, + "loose-envify": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz", + "from": "loose-envify@>=1.1.0 <2.0.0" + }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "from": "media-typer@0.3.0" + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "from": "merge-descriptors@1.0.1" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "from": "methods@>=1.1.2 <1.2.0" + }, + "mime": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz", + "from": "mime@1.3.4" + }, + "mime-db": { + "version": "1.27.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz", + "from": "mime-db@>=1.27.0 <1.28.0" + }, + "mime-types": { + "version": "2.1.15", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.15.tgz", + "from": "mime-types@>=2.1.11 <2.2.0" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "from": "ms@2.0.0" + }, + "negotiator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", + "from": "negotiator@0.6.1" + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "from": "object-assign@>=4.0.0 <5.0.0" + }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "from": "on-finished@>=2.3.0 <2.4.0" + }, + "parseurl": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.1.tgz", + "from": "parseurl@>=1.3.1 <1.4.0" + }, + "path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "from": "path-to-regexp@0.1.7" + }, + "proxy-addr": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.4.tgz", + "from": "proxy-addr@>=1.1.4 <1.2.0" + }, + "qs": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz", + "from": "qs@6.4.0" + }, + "range-parser": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", + "from": "range-parser@>=1.2.0 <1.3.0" + }, + "raw-body": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.2.0.tgz", + "from": "raw-body@>=2.2.0 <2.3.0" + }, + "redux": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/redux/-/redux-3.7.1.tgz", + "from": "redux@>=3.4.0 <4.0.0" + }, + "send": { + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/send/-/send-0.15.3.tgz", + "from": "send@0.15.3" + }, + "serve-static": { + "version": "1.12.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.12.3.tgz", + "from": "serve-static@1.12.3" + }, + "setprototypeof": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", + "from": "setprototypeof@1.0.3" + }, + "statuses": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", + "from": "statuses@>=1.3.1 <1.4.0" + }, + "symbol-observable": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.4.tgz", + "from": "symbol-observable@>=1.0.2 <2.0.0" + }, + "type-is": { + "version": "1.6.15", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", + "from": "type-is@>=1.6.15 <1.7.0" + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "from": "unpipe@>=1.0.0 <1.1.0" + }, + "utils-merge": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz", + "from": "utils-merge@1.0.0" + }, + "uuid": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", + "from": "uuid@>=3.0.1 <4.0.0" + }, + "vary": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.1.tgz", + "from": "vary@>=1.0.0 <2.0.0" + }, + "whatwg-fetch": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", + "from": "whatwg-fetch@>=2.0.0 <3.0.0" + } + } +} diff --git a/packages/rocketchat-graphql/package.js b/packages/rocketchat-graphql/package.js new file mode 100644 index 000000000000..37791a9b9c39 --- /dev/null +++ b/packages/rocketchat-graphql/package.js @@ -0,0 +1,27 @@ +Package.describe({ + name: 'rocketchat:graphql', + version: '0.0.1', + summary: 'GraphQL API', + git: '' +}); + +Package.onUse(function(api) { + api.use([ + 'underscore', + 'ecmascript', + 'rocketchat:lib', + 'rocketchat:api' + ]); + + api.addFiles('server/api.js', 'server'); +}); + +Npm.depends({ + 'apollo-client': '1.6.0', + cors: '2.8.3', + express: '4.15.3', + graphql: '0.10.3', + 'graphql-server-express': '0.9.0', + 'graphql-tools': '1.0.0', + 'body-parser': '1.17.2' +}); diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js new file mode 100644 index 000000000000..295b777518cc --- /dev/null +++ b/packages/rocketchat-graphql/server/api.js @@ -0,0 +1,36 @@ +import { graphqlExpress, graphiqlExpress } from 'graphql-server-express'; +import bodyParser from 'body-parser'; +import express from 'express'; +import cors from 'cors'; +import { Meteor } from 'meteor/meteor'; +import { WebApp } from 'meteor/webapp'; + +import { executableSchema } from './schema'; + +// the Meteor GraphQL server is an Express server +const graphQLServer = express(); + +graphQLServer.use(cors()); +graphQLServer.use(bodyParser.urlencoded({ extended: true })); + +graphQLServer.use( + '/graphql', + bodyParser.json(), + graphqlExpress(() => ({ + schema: executableSchema, + context: {}, + formatError: e => ({ + message: e.message, + locations: e.locations, + path: e.path + }), + debug: Meteor.isDevelopment + }))); + +graphQLServer.use('/graphiql', graphiqlExpress({ + endpointURL: '/graphql' +})); + + +// this binds the specified paths to the Express server running Apollo + GraphiQL +WebApp.connectHandlers.use(graphQLServer); diff --git a/packages/rocketchat-graphql/server/helpers/findChannelByIdAndUser.js b/packages/rocketchat-graphql/server/helpers/findChannelByIdAndUser.js new file mode 100644 index 000000000000..b36f972203e6 --- /dev/null +++ b/packages/rocketchat-graphql/server/helpers/findChannelByIdAndUser.js @@ -0,0 +1,8 @@ +export function findChannelByIdAndUser({ params, options = {} }) { + const sub = RocketChat.models.Subscriptions.findOne({ + rid: params.roomId, + 'u._id': params.userId + }, options); + + return sub; +} diff --git a/packages/rocketchat-graphql/server/helpers/property.js b/packages/rocketchat-graphql/server/helpers/property.js new file mode 100644 index 000000000000..65485cae9868 --- /dev/null +++ b/packages/rocketchat-graphql/server/helpers/property.js @@ -0,0 +1,3 @@ +export function property(key) { + return (object) => object == null ? undefined : object[key]; +} diff --git a/packages/rocketchat-graphql/server/schema.js b/packages/rocketchat-graphql/server/schema.js new file mode 100644 index 000000000000..8bf5a3bb1dda --- /dev/null +++ b/packages/rocketchat-graphql/server/schema.js @@ -0,0 +1,179 @@ +import { + makeExecutableSchema +} from 'graphql-tools'; + +import { + property +} from './helpers/property'; + +import { + findChannelByIdAndUser +} from './helpers/findChannelByIdAndUser'; + +// mys:admin +const testUser = 'fnw4B4suFsTXf8rZq'; + +const schema = ` + type schema { + query: Query + } + + type Query { + channels(filter: ChannelFilter = { + privacy: ALL, + joinedChannels: false, + sortBy: NAME + }): [Channel] + } + + type Channel { + id: String! + name: String + description: String + announcement: String + topic: String + members: [Member] + owners: [Member] + numberOfMembers: Int + numberOfMessages: Int + readOnly: Boolean + direct: Boolean + privateChannel: Boolean + favourite: Boolean + unseenMessages: Int + } + + enum Privacy { + PRIVATE + PUBLIC + ALL + } + + enum ChannelSort { + NAME + NUMBER_OF_MESSAGES + } + + input ChannelFilter { + nameFilter: String + privacy: Privacy + joinedChannels: Boolean + sortBy: ChannelSort + } + + type Member { + id: String! + name: String + } +`; + +const resolvers = { + Query: { + channels: (root, args) => { + const query = {}; + const options = { + sort: { + name: 1 + }, + fields: { + t: 1, + name: 1, + description: 1, + announcement: 1, + topic: 1, + usernames: 1, + msgs: 1, + ro: 1, + u: 1, + archived: 1 + } + }; + + // Filter + if (typeof args.filter !== 'undefined') { + // sortBy + if (args.filter.sortBy === 'NUMBER_OF_MESSAGES') { + options.sort = { + msgs: -1 + }; + } + + // privacy + switch (args.filter.privacy) { + case 'PRIVATE': + query.t = 'p'; + break; + case 'PUBLIC': + query.t = { + $ne: 'p' + }; + break; + } + } + + return RocketChat.models.Rooms.find(query, options).fetch(); + } + }, + Channel: { + id: property('_id'), + members: (root) => { + return root.usernames.map( + username => RocketChat.models.Users.findOneByUsername(username, { + fields: { + name: 1 + } + }) + ); + }, + owners: (root) => { + // there might be no owner + if (!root.u) { + return []; + } + + return [RocketChat.models.Users.findOneByUsername(root.u.username, { + fields: { + name: 1 + } + })]; + }, + numberOfMembers: (root) => (root.usernames || []).length, + numberOfMessages: property('msgs'), + readOnly: (root) => root.ro === true, + direct: (root) => root.t === 'd', + privateChannel: (root) => root.t === 'p', + favourite: (root) => { + const room = findChannelByIdAndUser({ + params: { + roomId: root._id, + userId: testUser + }, + options: { fields: { f: 1 }} + }); + + return room && room.f === true; + }, + unseenMessages: (root) => { + const room = findChannelByIdAndUser({ + params: { + roomId: root._id, + userId: testUser + }, + options: { fields: { unread: 1 }} + }); + + return (room || {}).unread; + } + }, + Member: { + id: property('_id') + } +}; + +export const executableSchema = makeExecutableSchema({ + typeDefs: [schema], + resolvers, + logger: { + log: (e) => console.log(e) + } +}); From 42ed8a429328ecd2bff82a260b77267454378439 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 29 Jun 2017 17:40:24 +0100 Subject: [PATCH 02/42] WIP --- packages/rocketchat-graphql/server/api.js | 4 +- .../server/mocks/accounts/graphql-api.js | 9 + .../server/mocks/accounts/server.js | 14 ++ packages/rocketchat-graphql/server/schema.js | 227 +++++++++++++++--- 4 files changed, 217 insertions(+), 37 deletions(-) create mode 100644 packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js create mode 100644 packages/rocketchat-graphql/server/mocks/accounts/server.js diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index 295b777518cc..040845247a44 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -18,7 +18,9 @@ graphQLServer.use( bodyParser.json(), graphqlExpress(() => ({ schema: executableSchema, - context: {}, + context: { + models: RocketChat.models + }, formatError: e => ({ message: e.message, locations: e.locations, diff --git a/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js b/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js new file mode 100644 index 000000000000..ac01fd1b681a --- /dev/null +++ b/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js @@ -0,0 +1,9 @@ +export const authenticated = (Accounts, func) => (async(root, args, context, info) => { + const userObject = await Accounts.resumeSession(); + + if (userObject === null) { + throw new Error('Invalid or expired token!'); + } + + return await func(root, args, Object.assign(context, { user: userObject }), info); +}); diff --git a/packages/rocketchat-graphql/server/mocks/accounts/server.js b/packages/rocketchat-graphql/server/mocks/accounts/server.js new file mode 100644 index 000000000000..2d472b58e125 --- /dev/null +++ b/packages/rocketchat-graphql/server/mocks/accounts/server.js @@ -0,0 +1,14 @@ +const loggedOut = false; + +const AccountsServer = { + async resumeSession() { + if (loggedOut) { + throw new Error('User not found'); + } + // User credentials + // mys:admin + return RocketChat.models.Users.findOneById('fnw4B4suFsTXf8rZq'); + } +}; + +export default AccountsServer; diff --git a/packages/rocketchat-graphql/server/schema.js b/packages/rocketchat-graphql/server/schema.js index 8bf5a3bb1dda..d60196d79faf 100644 --- a/packages/rocketchat-graphql/server/schema.js +++ b/packages/rocketchat-graphql/server/schema.js @@ -1,7 +1,12 @@ +/* global processWebhookMessage */ + import { makeExecutableSchema } from 'graphql-tools'; +import { authenticated } from './mocks/accounts/graphql-api'; +import AccountsServer from './mocks/accounts/server'; + import { property } from './helpers/property'; @@ -10,12 +15,11 @@ import { findChannelByIdAndUser } from './helpers/findChannelByIdAndUser'; -// mys:admin -const testUser = 'fnw4B4suFsTXf8rZq'; const schema = ` type schema { query: Query + mutation: Mutation } type Query { @@ -24,11 +28,18 @@ const schema = ` joinedChannels: false, sortBy: NAME }): [Channel] + channelByName(name: String!, isDirect: Boolean!): Channel + channelsByUser(userId: String!): [Channel] + messages(channelId: String): MessagesWithCursor + } + + type Mutation { + sendMessage(channelId: String!, content: String!): Message } type Channel { id: String! - name: String + name: String description: String announcement: String topic: String @@ -44,7 +55,7 @@ const schema = ` } enum Privacy { - PRIVATE + PRIVATE PUBLIC ALL } @@ -65,28 +76,54 @@ const schema = ` id: String! name: String } + + type MessagesWithCursor { + cursor: String + channel: Channel + messagesArray: [Message] + } + + type Message { + id: String + author: Member + content: String + creationTime: String + fromServer: Boolean + userRef: [Member] + channelRef: [Channel] + reactions: [Reaction] + # TODO + tags: [String] + } + + type Reaction { + username: String + icon: String + } `; +const roomPublicFields = { + t: 1, + name: 1, + description: 1, + announcement: 1, + topic: 1, + usernames: 1, + msgs: 1, + ro: 1, + u: 1, + archived: 1 +}; + const resolvers = { Query: { - channels: (root, args) => { + channels: authenticated(AccountsServer, (root, args, { models }) => { const query = {}; const options = { sort: { name: 1 }, - fields: { - t: 1, - name: 1, - description: 1, - announcement: 1, - topic: 1, - usernames: 1, - msgs: 1, - ro: 1, - u: 1, - archived: 1 - } + fields: roomPublicFields }; // Filter @@ -111,53 +148,112 @@ const resolvers = { } } - return RocketChat.models.Rooms.find(query, options).fetch(); - } + return models.Rooms.find(query, options).fetch(); + }), + channelByName: authenticated(AccountsServer, (root, { name, isDirect }, { models }) => { + const query = { + name + }; + + if (isDirect === true) { + query.c = 'd'; + } + + return models.Rooms.findOne(query, { + fields: roomPublicFields + }); + }), + channelsByUser: authenticated(AccountsServer, (root, { userId }, { models }) => { + const user = models.Users.findOneById(userId); + + if (!user) { + // TODO: + throw new Error('No user'); + } + + return models.Rooms.find({ + 'usernames': { + $in: user.username + } + }, { + sort: { + name: 1 + }, + fields: roomPublicFields + }).fetch(); + }), + messages: authenticated(AccountsServer, (root, args, { models }) => { + if (!args.channelId) { + console.error('messages query must be called with channelId'); + return null; + } + + const query = {}; + + if (args.channelId) { + query.rid = args.channelId; + } + + const messagesArray = models.Messages.find(query).fetch(); + const channel = models.Rooms.findOne(args.channelId); + + return { + cursor: 'CURSOR', + channel, + messagesArray + }; + }) + }, + Mutation: { + sendMessage: authenticated(AccountsServer, (root, { channelId, content }, { user }) => { + const messageReturn = processWebhookMessage({ + roomId: channelId, + text: content + }, user)[0]; + + if (!messageReturn) { + throw new Error('Unknown error'); + } + + return messageReturn.message; + }) }, Channel: { id: property('_id'), - members: (root) => { + members: (root, args, { models }) => { return root.usernames.map( - username => RocketChat.models.Users.findOneByUsername(username, { - fields: { - name: 1 - } - }) + username => models.Users.findOneByUsername(username) ); }, - owners: (root) => { + owners: (root, args, { models }) => { // there might be no owner if (!root.u) { - return []; + return; } - return [RocketChat.models.Users.findOneByUsername(root.u.username, { - fields: { - name: 1 - } - })]; + return [models.Users.findOneByUsername(root.u.username)]; }, numberOfMembers: (root) => (root.usernames || []).length, numberOfMessages: property('msgs'), readOnly: (root) => root.ro === true, direct: (root) => root.t === 'd', privateChannel: (root) => root.t === 'p', - favourite: (root) => { + favourite: (root, args, { user }) => { const room = findChannelByIdAndUser({ params: { roomId: root._id, - userId: testUser + userId: user._id }, options: { fields: { f: 1 }} }); return room && room.f === true; }, - unseenMessages: (root) => { + unseenMessages: (root, args, { user }) => { const room = findChannelByIdAndUser({ params: { roomId: root._id, - userId: testUser + userId: user._id }, options: { fields: { unread: 1 }} }); @@ -167,6 +263,65 @@ const resolvers = { }, Member: { id: property('_id') + }, + Message: { + id: property('_id'), + content: property('msg'), + creationTime: property('ts'), + author: (root, args, { models }) => { + return models.Users.findOne(root.u._id); + }, + fromServer: (root) => typeof root.t !== 'undefined', // on a message sent by user `true` otherwise `false` + channelRef: (root, args, { models }) => { + if (!root.channels) { + return; + } + + return models.Rooms.find({ + _id: { + $in: root.channels.map(c => c._id) + } + }, { + sort: { + name: 1 + } + }).fetch(); + }, + userRef: (root, args, { models }) => { + if (!root.mentions) { + return; + } + + return models.Users.find({ + _id: { + $in: root.mentions.map(c => c._id) + } + }, { + sort: { + username: 1 + } + }).fetch(); + }, + reactions: (root) => { + if (!root.reactions || Object.keys(root.reactions).length === 0) { + return; + } + + const reactions = []; + + Object.keys(root.reactions).forEach(icon => { + root.reactions[icon].usernames.forEach(username => { + reactions.push({ + icon, + username + }); + }); + }); + + return reactions; + }, + // TODO + tags: () => {} } }; From b8687217af6242a8aa4466ca73b0a91406966a42 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 29 Jun 2017 20:17:49 +0100 Subject: [PATCH 03/42] WIP --- packages/rocketchat-graphql/server/schema.js | 98 +++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/packages/rocketchat-graphql/server/schema.js b/packages/rocketchat-graphql/server/schema.js index d60196d79faf..c89d5521ee52 100644 --- a/packages/rocketchat-graphql/server/schema.js +++ b/packages/rocketchat-graphql/server/schema.js @@ -4,7 +4,10 @@ import { makeExecutableSchema } from 'graphql-tools'; +import { Meteor } from 'meteor/meteor'; + import { authenticated } from './mocks/accounts/graphql-api'; + import AccountsServer from './mocks/accounts/server'; import { @@ -34,7 +37,11 @@ const schema = ` } type Mutation { + setStatus(status: UserStatus!): Member sendMessage(channelId: String!, content: String!): Message + editMessage(id: MessageIdentifier!, content: String!): Message + deleteMessage(id: MessageIdentifier!): Message + createChannel(name: String!, private: Boolean = false, readOnly: Boolean = false, membersId: [String!]): Channel } type Channel { @@ -72,9 +79,18 @@ const schema = ` sortBy: ChannelSort } + enum UserStatus { + ONLINE + AWAY + BUSY + INVISIBLE + } + type Member { id: String! name: String + # TODO: change to UserStatus + status: String } type MessagesWithCursor { @@ -83,10 +99,16 @@ const schema = ` messagesArray: [Message] } + input MessageIdentifier { + channelId: String! + messageId: String! + } + type Message { id: String author: Member content: String + channel: Channel creationTime: String fromServer: Boolean userRef: [Member] @@ -216,6 +238,76 @@ const resolvers = { } return messageReturn.message; + }), + editMessage: authenticated(AccountsServer, (root, { id, content }, { user, models }) => { + const msg = models.Messages.findOneById(id.messageId); + + //Ensure the message exists + if (!msg) { + throw new Error(`No message found with the id of "${ id.messageId }".`); + } + + if (id.channelId !== msg.rid) { + throw new Error('The channel id provided does not match where the message is from.'); + } + + //Permission checks are already done in the updateMessage method, so no need to duplicate them + Meteor.runAsUser(user._id, () => { + Meteor.call('updateMessage', { _id: msg._id, msg: content, rid: msg.rid }); + }); + + return models.Messages.findOneById(msg._id); + }), + deleteMessage: authenticated(AccountsServer, (root, { id }, { models, user }) => { + const msg = models.Messages.findOneById(id.messageId, { fields: { u: 1, rid: 1 }}); + + if (!msg) { + throw new Error(`No message found with the id of "${ id.messageId }".`); + } + + if (id.channelId !== msg.rid) { + throw new Error('The room id provided does not match where the message is from.'); + } + + Meteor.runAsUser(user._id, () => { + Meteor.call('deleteMessage', { _id: msg._id }); + }); + + return msg; + }), + setStatus: authenticated(AccountsServer, (root, { status }, { models, user }) => { + models.Users.update(user._id, { + $set: { + status: status.toLowerCase() + } + }); + + return models.Users.findOne(user._id); + }), + createChannel: authenticated(AccountsServer, (root, args, { models, user }) => { + if (!RocketChat.authz.hasPermission(user._id, 'create-c')) { + return RocketChat.API.v1.unauthorized(); + } + + if (!args.name) { + throw new Error('Param "name" is required'); + } + + if (args.membersId && !_.isArray(args.membersId)) { + throw new Error('Param "membersId" must be an array if provided'); + } + + let readOnly = false; + if (typeof args.readOnly !== 'undefined') { + readOnly = args.readOnly; + } + + let id; + Meteor.runAsUser(user._id, () => { + id = Meteor.call('createChannel', args.name, args.membersId ? args.membersId : [], readOnly); + }); + + return models.Rooms.findOneById(id.rid, { fields: RocketChat.API.v1.defaultFieldsToExclude }); }) }, Channel: { @@ -262,7 +354,8 @@ const resolvers = { } }, Member: { - id: property('_id') + id: property('_id'), + status: ({status}) => status.toUpperCase() }, Message: { id: property('_id'), @@ -271,6 +364,9 @@ const resolvers = { author: (root, args, { models }) => { return models.Users.findOne(root.u._id); }, + channel: (root, args, { models }) => { + return models.Rooms.findOne(root.rid); + }, fromServer: (root) => typeof root.t !== 'undefined', // on a message sent by user `true` otherwise `false` channelRef: (root, args, { models }) => { if (!root.channels) { From c195f46ad570d96a208666a29993c5b86cafe8e8 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Fri, 30 Jun 2017 17:32:16 +0100 Subject: [PATCH 04/42] Separate features --- .../.npm/package/npm-shrinkwrap.json | 20 +- packages/rocketchat-graphql/package.js | 5 +- packages/rocketchat-graphql/server/schema.js | 390 +----------------- .../server/schemas/channels/Channel-type.js | 67 +++ .../schemas/channels/ChannelFilter-input.js | 8 + .../schemas/channels/ChannelSort-enum.js | 6 + .../server/schemas/channels/Privacy-enum.js | 7 + .../server/schemas/channels/channelByName.js | 27 ++ .../server/schemas/channels/channels.js | 51 +++ .../server/schemas/channels/channelsByUser.js | 33 ++ .../server/schemas/channels/createChannel.js | 41 ++ .../server/schemas/channels/index.js | 38 ++ .../server/schemas/channels/settings.js | 12 + .../server/schemas/messages/Message-type.js | 82 ++++ .../messages/MessageIdentifier-input.js | 6 + .../messages/MessagesWithCursor-type.js | 7 + .../server/schemas/messages/Reaction-type.js | 6 + .../server/schemas/messages/deleteMessage.js | 32 ++ .../server/schemas/messages/editMessage.js | 34 ++ .../server/schemas/messages/index.js | 38 ++ .../server/schemas/messages/messages.js | 34 ++ .../server/schemas/messages/sendMessage.js | 27 ++ 22 files changed, 591 insertions(+), 380 deletions(-) create mode 100644 packages/rocketchat-graphql/server/schemas/channels/Channel-type.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/channelByName.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/channels.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/createChannel.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/index.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/settings.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/Message-type.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/Reaction-type.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/editMessage.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/index.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/messages.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/sendMessage.js diff --git a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json index 99bd39438b7f..1c663c3f6914 100644 --- a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json @@ -55,6 +55,11 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.7.tgz", "from": "debug@2.6.7" }, + "deepmerge": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-1.4.4.tgz", + "from": "deepmerge@>=1.3.2 <2.0.0" + }, "depd": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.0.tgz", @@ -141,9 +146,9 @@ "from": "graphql-tag@>=2.0.0 <3.0.0" }, "graphql-tools": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-1.0.0.tgz", - "from": "graphql-tools@1.0.0" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-1.1.0.tgz", + "from": "graphql-tools@1.1.0" }, "http-errors": { "version": "1.6.1", @@ -171,8 +176,8 @@ "from": "iterall@>=1.1.0 <2.0.0" }, "js-tokens": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.1.tgz", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", "from": "js-tokens@>=3.0.0 <4.0.0" }, "lodash": { @@ -200,6 +205,11 @@ "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", "from": "merge-descriptors@1.0.1" }, + "merge-graphql-schemas": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/merge-graphql-schemas/-/merge-graphql-schemas-1.1.0.tgz", + "from": "merge-graphql-schemas@1.1.0" + }, "methods": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", diff --git a/packages/rocketchat-graphql/package.js b/packages/rocketchat-graphql/package.js index 37791a9b9c39..3c29cdb70911 100644 --- a/packages/rocketchat-graphql/package.js +++ b/packages/rocketchat-graphql/package.js @@ -22,6 +22,7 @@ Npm.depends({ express: '4.15.3', graphql: '0.10.3', 'graphql-server-express': '0.9.0', - 'graphql-tools': '1.0.0', - 'body-parser': '1.17.2' + 'graphql-tools': '1.1.0', + 'body-parser': '1.17.2', + 'merge-graphql-schemas': '1.1.0' }); diff --git a/packages/rocketchat-graphql/server/schema.js b/packages/rocketchat-graphql/server/schema.js index c89d5521ee52..dd1fbb53097f 100644 --- a/packages/rocketchat-graphql/server/schema.js +++ b/packages/rocketchat-graphql/server/schema.js @@ -1,10 +1,8 @@ -/* global processWebhookMessage */ - import { makeExecutableSchema } from 'graphql-tools'; -import { Meteor } from 'meteor/meteor'; +import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; import { authenticated } from './mocks/accounts/graphql-api'; @@ -14,69 +12,12 @@ import { property } from './helpers/property'; -import { - findChannelByIdAndUser -} from './helpers/findChannelByIdAndUser'; - - -const schema = ` - type schema { - query: Query - mutation: Mutation - } - - type Query { - channels(filter: ChannelFilter = { - privacy: ALL, - joinedChannels: false, - sortBy: NAME - }): [Channel] - channelByName(name: String!, isDirect: Boolean!): Channel - channelsByUser(userId: String!): [Channel] - messages(channelId: String): MessagesWithCursor - } +import * as channels from './schemas/channels'; +import * as messages from './schemas/messages'; +const rootSchema = ` type Mutation { setStatus(status: UserStatus!): Member - sendMessage(channelId: String!, content: String!): Message - editMessage(id: MessageIdentifier!, content: String!): Message - deleteMessage(id: MessageIdentifier!): Message - createChannel(name: String!, private: Boolean = false, readOnly: Boolean = false, membersId: [String!]): Channel - } - - type Channel { - id: String! - name: String - description: String - announcement: String - topic: String - members: [Member] - owners: [Member] - numberOfMembers: Int - numberOfMessages: Int - readOnly: Boolean - direct: Boolean - privateChannel: Boolean - favourite: Boolean - unseenMessages: Int - } - - enum Privacy { - PRIVATE - PUBLIC - ALL - } - - enum ChannelSort { - NAME - NUMBER_OF_MESSAGES - } - - input ChannelFilter { - nameFilter: String - privacy: Privacy - joinedChannels: Boolean - sortBy: ChannelSort } enum UserStatus { @@ -92,189 +33,10 @@ const schema = ` # TODO: change to UserStatus status: String } - - type MessagesWithCursor { - cursor: String - channel: Channel - messagesArray: [Message] - } - - input MessageIdentifier { - channelId: String! - messageId: String! - } - - type Message { - id: String - author: Member - content: String - channel: Channel - creationTime: String - fromServer: Boolean - userRef: [Member] - channelRef: [Channel] - reactions: [Reaction] - # TODO - tags: [String] - } - - type Reaction { - username: String - icon: String - } `; -const roomPublicFields = { - t: 1, - name: 1, - description: 1, - announcement: 1, - topic: 1, - usernames: 1, - msgs: 1, - ro: 1, - u: 1, - archived: 1 -}; - -const resolvers = { - Query: { - channels: authenticated(AccountsServer, (root, args, { models }) => { - const query = {}; - const options = { - sort: { - name: 1 - }, - fields: roomPublicFields - }; - - // Filter - if (typeof args.filter !== 'undefined') { - // sortBy - if (args.filter.sortBy === 'NUMBER_OF_MESSAGES') { - options.sort = { - msgs: -1 - }; - } - - // privacy - switch (args.filter.privacy) { - case 'PRIVATE': - query.t = 'p'; - break; - case 'PUBLIC': - query.t = { - $ne: 'p' - }; - break; - } - } - - return models.Rooms.find(query, options).fetch(); - }), - channelByName: authenticated(AccountsServer, (root, { name, isDirect }, { models }) => { - const query = { - name - }; - - if (isDirect === true) { - query.c = 'd'; - } - - return models.Rooms.findOne(query, { - fields: roomPublicFields - }); - }), - channelsByUser: authenticated(AccountsServer, (root, { userId }, { models }) => { - const user = models.Users.findOneById(userId); - - if (!user) { - // TODO: - throw new Error('No user'); - } - - return models.Rooms.find({ - 'usernames': { - $in: user.username - } - }, { - sort: { - name: 1 - }, - fields: roomPublicFields - }).fetch(); - }), - messages: authenticated(AccountsServer, (root, args, { models }) => { - if (!args.channelId) { - console.error('messages query must be called with channelId'); - return null; - } - - const query = {}; - - if (args.channelId) { - query.rid = args.channelId; - } - - const messagesArray = models.Messages.find(query).fetch(); - const channel = models.Rooms.findOne(args.channelId); - - return { - cursor: 'CURSOR', - channel, - messagesArray - }; - }) - }, +const rootResolvers = { Mutation: { - sendMessage: authenticated(AccountsServer, (root, { channelId, content }, { user }) => { - const messageReturn = processWebhookMessage({ - roomId: channelId, - text: content - }, user)[0]; - - if (!messageReturn) { - throw new Error('Unknown error'); - } - - return messageReturn.message; - }), - editMessage: authenticated(AccountsServer, (root, { id, content }, { user, models }) => { - const msg = models.Messages.findOneById(id.messageId); - - //Ensure the message exists - if (!msg) { - throw new Error(`No message found with the id of "${ id.messageId }".`); - } - - if (id.channelId !== msg.rid) { - throw new Error('The channel id provided does not match where the message is from.'); - } - - //Permission checks are already done in the updateMessage method, so no need to duplicate them - Meteor.runAsUser(user._id, () => { - Meteor.call('updateMessage', { _id: msg._id, msg: content, rid: msg.rid }); - }); - - return models.Messages.findOneById(msg._id); - }), - deleteMessage: authenticated(AccountsServer, (root, { id }, { models, user }) => { - const msg = models.Messages.findOneById(id.messageId, { fields: { u: 1, rid: 1 }}); - - if (!msg) { - throw new Error(`No message found with the id of "${ id.messageId }".`); - } - - if (id.channelId !== msg.rid) { - throw new Error('The room id provided does not match where the message is from.'); - } - - Meteor.runAsUser(user._id, () => { - Meteor.call('deleteMessage', { _id: msg._id }); - }); - - return msg; - }), setStatus: authenticated(AccountsServer, (root, { status }, { models, user }) => { models.Users.update(user._id, { $set: { @@ -283,144 +45,26 @@ const resolvers = { }); return models.Users.findOne(user._id); - }), - createChannel: authenticated(AccountsServer, (root, args, { models, user }) => { - if (!RocketChat.authz.hasPermission(user._id, 'create-c')) { - return RocketChat.API.v1.unauthorized(); - } - - if (!args.name) { - throw new Error('Param "name" is required'); - } - - if (args.membersId && !_.isArray(args.membersId)) { - throw new Error('Param "membersId" must be an array if provided'); - } - - let readOnly = false; - if (typeof args.readOnly !== 'undefined') { - readOnly = args.readOnly; - } - - let id; - Meteor.runAsUser(user._id, () => { - id = Meteor.call('createChannel', args.name, args.membersId ? args.membersId : [], readOnly); - }); - - return models.Rooms.findOneById(id.rid, { fields: RocketChat.API.v1.defaultFieldsToExclude }); }) }, - Channel: { - id: property('_id'), - members: (root, args, { models }) => { - return root.usernames.map( - username => models.Users.findOneByUsername(username) - ); - }, - owners: (root, args, { models }) => { - // there might be no owner - if (!root.u) { - return; - } - - return [models.Users.findOneByUsername(root.u.username)]; - }, - numberOfMembers: (root) => (root.usernames || []).length, - numberOfMessages: property('msgs'), - readOnly: (root) => root.ro === true, - direct: (root) => root.t === 'd', - privateChannel: (root) => root.t === 'p', - favourite: (root, args, { user }) => { - const room = findChannelByIdAndUser({ - params: { - roomId: root._id, - userId: user._id - }, - options: { fields: { f: 1 }} - }); - - return room && room.f === true; - }, - unseenMessages: (root, args, { user }) => { - const room = findChannelByIdAndUser({ - params: { - roomId: root._id, - userId: user._id - }, - options: { fields: { unread: 1 }} - }); - - return (room || {}).unread; - } - }, Member: { id: property('_id'), status: ({status}) => status.toUpperCase() - }, - Message: { - id: property('_id'), - content: property('msg'), - creationTime: property('ts'), - author: (root, args, { models }) => { - return models.Users.findOne(root.u._id); - }, - channel: (root, args, { models }) => { - return models.Rooms.findOne(root.rid); - }, - fromServer: (root) => typeof root.t !== 'undefined', // on a message sent by user `true` otherwise `false` - channelRef: (root, args, { models }) => { - if (!root.channels) { - return; - } - - return models.Rooms.find({ - _id: { - $in: root.channels.map(c => c._id) - } - }, { - sort: { - name: 1 - } - }).fetch(); - }, - userRef: (root, args, { models }) => { - if (!root.mentions) { - return; - } - - return models.Users.find({ - _id: { - $in: root.mentions.map(c => c._id) - } - }, { - sort: { - username: 1 - } - }).fetch(); - }, - reactions: (root) => { - if (!root.reactions || Object.keys(root.reactions).length === 0) { - return; - } - - const reactions = []; - - Object.keys(root.reactions).forEach(icon => { - root.reactions[icon].usernames.forEach(username => { - reactions.push({ - icon, - username - }); - }); - }); - - return reactions; - }, - // TODO - tags: () => {} } }; +const schema = mergeTypes([ + rootSchema, + channels.schema, + messages.schema +]); + +const resolvers = mergeResolvers([ + rootResolvers, + channels.resolvers, + messages.resolvers +]); + export const executableSchema = makeExecutableSchema({ typeDefs: [schema], resolvers, diff --git a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js new file mode 100644 index 000000000000..0d6dbac4512f --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js @@ -0,0 +1,67 @@ +import { property } from '../../helpers/property'; +import { findChannelByIdAndUser } from '../../helpers/findChannelByIdAndUser'; + +export const schema = ` + type Channel { + id: String! + name: String + description: String + announcement: String + topic: String + members: [Member] + owners: [Member] + numberOfMembers: Int + numberOfMessages: Int + readOnly: Boolean + direct: Boolean + privateChannel: Boolean + favourite: Boolean + unseenMessages: Int + } +`; + +export const resolver = { + Channel: { + id: property('_id'), + members: (root, args, { models }) => { + return root.usernames.map( + username => models.Users.findOneByUsername(username) + ); + }, + owners: (root, args, { models }) => { + // there might be no owner + if (!root.u) { + return; + } + + return [models.Users.findOneByUsername(root.u.username)]; + }, + numberOfMembers: (root) => (root.usernames || []).length, + numberOfMessages: property('msgs'), + readOnly: (root) => root.ro === true, + direct: (root) => root.t === 'd', + privateChannel: (root) => root.t === 'p', + favourite: (root, args, { user }) => { + const room = findChannelByIdAndUser({ + params: { + roomId: root._id, + userId: user._id + }, + options: { fields: { f: 1 }} + }); + + return room && room.f === true; + }, + unseenMessages: (root, args, { user }) => { + const room = findChannelByIdAndUser({ + params: { + roomId: root._id, + userId: user._id + }, + options: { fields: { unread: 1 }} + }); + + return (room || {}).unread; + } + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.js b/packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.js new file mode 100644 index 000000000000..b80d4c680a95 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.js @@ -0,0 +1,8 @@ +export const schema = ` + input ChannelFilter { + nameFilter: String + privacy: Privacy + joinedChannels: Boolean + sortBy: ChannelSort + } +`; diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.js b/packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.js new file mode 100644 index 000000000000..beecdedd89ef --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.js @@ -0,0 +1,6 @@ +export const schema = ` + enum ChannelSort { + NAME + NUMBER_OF_MESSAGES + } +`; diff --git a/packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.js b/packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.js new file mode 100644 index 000000000000..d0cd977a9470 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.js @@ -0,0 +1,7 @@ +export const schema = ` + enum Privacy { + PRIVATE + PUBLIC + ALL + } +`; diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelByName.js b/packages/rocketchat-graphql/server/schemas/channels/channelByName.js new file mode 100644 index 000000000000..9e0f0ca3c39c --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/channelByName.js @@ -0,0 +1,27 @@ +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; +import { roomPublicFields } from './settings'; + +export const schema = ` + type Query { + channelByName(name: String!, isDirect: Boolean!): Channel + } +`; + +export const resolver = { + Query: { + channelByName: authenticated(AccountsServer, (root, { name, isDirect }, { models }) => { + const query = { + name + }; + + if (isDirect === true) { + query.c = 'd'; + } + + return models.Rooms.findOne(query, { + fields: roomPublicFields + }); + }) + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/channels.js b/packages/rocketchat-graphql/server/schemas/channels/channels.js new file mode 100644 index 000000000000..f53979adf037 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/channels.js @@ -0,0 +1,51 @@ +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; +import { roomPublicFields } from './settings'; + +export const schema = ` + type Query { + channels(filter: ChannelFilter = { + privacy: ALL, + joinedChannels: false, + sortBy: NAME + }): [Channel] + } +`; + +export const resolver = { + Query: { + channels: authenticated(AccountsServer, (root, args, { models }) => { + const query = {}; + const options = { + sort: { + name: 1 + }, + fields: roomPublicFields + }; + + // Filter + if (typeof args.filter !== 'undefined') { + // sortBy + if (args.filter.sortBy === 'NUMBER_OF_MESSAGES') { + options.sort = { + msgs: -1 + }; + } + + // privacy + switch (args.filter.privacy) { + case 'PRIVATE': + query.t = 'p'; + break; + case 'PUBLIC': + query.t = { + $ne: 'p' + }; + break; + } + } + + return models.Rooms.find(query, options).fetch(); + }) + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js new file mode 100644 index 000000000000..98a888fe8970 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js @@ -0,0 +1,33 @@ +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; +import { roomPublicFields } from './settings'; + +export const schema = ` + type Query { + channelsByUser(userId: String!): [Channel] + } +`; + +export const resolver = { + Query: { + channelsByUser: authenticated(AccountsServer, (root, { userId }, { models }) => { + const user = models.Users.findOneById(userId); + + if (!user) { + // TODO: + throw new Error('No user'); + } + + return models.Rooms.find({ + 'usernames': { + $in: user.username + } + }, { + sort: { + name: 1 + }, + fields: roomPublicFields + }).fetch(); + }) + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/createChannel.js b/packages/rocketchat-graphql/server/schemas/channels/createChannel.js new file mode 100644 index 000000000000..736afdaf00c0 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/createChannel.js @@ -0,0 +1,41 @@ +import { Meteor } from 'meteor/meteor'; + +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; + +export const schema = ` + type Mutation { + createChannel(name: String!, private: Boolean = false, readOnly: Boolean = false, membersId: [String!]): Channel + } +`; + +export const resolver = { + Mutation: { + createChannel: authenticated(AccountsServer, (root, args, { models, user }) => { + if (!RocketChat.authz.hasPermission(user._id, 'create-c')) { + return RocketChat.API.v1.unauthorized(); + } + + if (!args.name) { + throw new Error('Param "name" is required'); + } + + if (args.membersId && !_.isArray(args.membersId)) { + throw new Error('Param "membersId" must be an array if provided'); + } + + let readOnly = false; + if (typeof args.readOnly !== 'undefined') { + readOnly = args.readOnly; + } + + let id; + Meteor.runAsUser(user._id, () => { + id = Meteor.call('createChannel', args.name, args.membersId ? args.membersId : [], readOnly); + }); + + return models.Rooms.findOneById(id.rid, { fields: RocketChat.API.v1.defaultFieldsToExclude }); + }) + } +}; + diff --git a/packages/rocketchat-graphql/server/schemas/channels/index.js b/packages/rocketchat-graphql/server/schemas/channels/index.js new file mode 100644 index 000000000000..25a1efcb4ebb --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/index.js @@ -0,0 +1,38 @@ +import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; + +// queries +import * as channels from './channels'; +import * as channelByName from './channelByName'; +import * as channelsByUser from './channelsByUser'; +// mutations +import * as createChannel from './createChannel'; +// types +import * as channelType from './Channel-type'; +import * as channelSort from './ChannelSort-enum'; +import * as channelFilter from './ChannelFilter-input'; +import * as Privacy from './Privacy-enum'; + +export const schema = mergeTypes([ + // queries + channels.schema, + channelByName.schema, + channelsByUser.schema, + // mutations + createChannel.schema, + // types + channelType.schema, + channelSort.schema, + channelFilter.schema, + Privacy.schema +]); + +export const resolvers = mergeResolvers([ + // queries + channels.resolver, + channelByName.resolver, + channelsByUser.resolver, + // mutations + createChannel.resolver, + // types + channelType.resolver +]); diff --git a/packages/rocketchat-graphql/server/schemas/channels/settings.js b/packages/rocketchat-graphql/server/schemas/channels/settings.js new file mode 100644 index 000000000000..7cace07a7cbc --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/settings.js @@ -0,0 +1,12 @@ +export const roomPublicFields = { + t: 1, + name: 1, + description: 1, + announcement: 1, + topic: 1, + usernames: 1, + msgs: 1, + ro: 1, + u: 1, + archived: 1 +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js new file mode 100644 index 000000000000..9513feb12e10 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js @@ -0,0 +1,82 @@ +import { property } from '../../helpers/property'; + +export const schema = ` + type Message { + id: String + author: Member + content: String + channel: Channel + creationTime: String + fromServer: Boolean + userRef: [Member] + channelRef: [Channel] + reactions: [Reaction] + # TODO + tags: [String] + } +`; + +export const resolver = { + Message: { + id: property('_id'), + content: property('msg'), + creationTime: property('ts'), + author: (root, args, { models }) => { + return models.Users.findOne(root.u._id); + }, + channel: (root, args, { models }) => { + return models.Rooms.findOne(root.rid); + }, + fromServer: (root) => typeof root.t !== 'undefined', // on a message sent by user `true` otherwise `false` + channelRef: (root, args, { models }) => { + if (!root.channels) { + return; + } + + return models.Rooms.find({ + _id: { + $in: root.channels.map(c => c._id) + } + }, { + sort: { + name: 1 + } + }).fetch(); + }, + userRef: (root, args, { models }) => { + if (!root.mentions) { + return; + } + + return models.Users.find({ + _id: { + $in: root.mentions.map(c => c._id) + } + }, { + sort: { + username: 1 + } + }).fetch(); + }, + reactions: (root) => { + if (!root.reactions || Object.keys(root.reactions).length === 0) { + return; + } + + const reactions = []; + + Object.keys(root.reactions).forEach(icon => { + root.reactions[icon].usernames.forEach(username => { + reactions.push({ + icon, + username + }); + }); + }); + + return reactions; + }, + // TODO + tags: () => {} + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.js b/packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.js new file mode 100644 index 000000000000..bb8571477bfe --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.js @@ -0,0 +1,6 @@ +export const schema = ` + input MessageIdentifier { + channelId: String! + messageId: String! + } +`; diff --git a/packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.js b/packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.js new file mode 100644 index 000000000000..b70b287321b8 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.js @@ -0,0 +1,7 @@ +export const schema = ` + type MessagesWithCursor { + cursor: String + channel: Channel + messagesArray: [Message] + } +`; diff --git a/packages/rocketchat-graphql/server/schemas/messages/Reaction-type.js b/packages/rocketchat-graphql/server/schemas/messages/Reaction-type.js new file mode 100644 index 000000000000..c337f52ce6bf --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/Reaction-type.js @@ -0,0 +1,6 @@ +export const schema = ` + type Reaction { + username: String + icon: String + } +`; diff --git a/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js b/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js new file mode 100644 index 000000000000..0b941817a8dd --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js @@ -0,0 +1,32 @@ +import { Meteor } from 'meteor/meteor'; + +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; + +export const schema = ` + type Mutation { + deleteMessage(id: MessageIdentifier!): Message + } +`; + +export const resolver = { + Mutation: { + deleteMessage: authenticated(AccountsServer, (root, { id }, { models, user }) => { + const msg = models.Messages.findOneById(id.messageId, { fields: { u: 1, rid: 1 }}); + + if (!msg) { + throw new Error(`No message found with the id of "${ id.messageId }".`); + } + + if (id.channelId !== msg.rid) { + throw new Error('The room id provided does not match where the message is from.'); + } + + Meteor.runAsUser(user._id, () => { + Meteor.call('deleteMessage', { _id: msg._id }); + }); + + return msg; + }) + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/editMessage.js b/packages/rocketchat-graphql/server/schemas/messages/editMessage.js new file mode 100644 index 000000000000..6eacb619f51d --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/editMessage.js @@ -0,0 +1,34 @@ +import { Meteor } from 'meteor/meteor'; + +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; + +export const schema = ` + type Mutation { + editMessage(id: MessageIdentifier!, content: String!): Message + } +`; + +export const resolver = { + Mutation: { + editMessage: authenticated(AccountsServer, (root, { id, content }, { user, models }) => { + const msg = models.Messages.findOneById(id.messageId); + + //Ensure the message exists + if (!msg) { + throw new Error(`No message found with the id of "${ id.messageId }".`); + } + + if (id.channelId !== msg.rid) { + throw new Error('The channel id provided does not match where the message is from.'); + } + + //Permission checks are already done in the updateMessage method, so no need to duplicate them + Meteor.runAsUser(user._id, () => { + Meteor.call('updateMessage', { _id: msg._id, msg: content, rid: msg.rid }); + }); + + return models.Messages.findOneById(msg._id); + }) + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/index.js b/packages/rocketchat-graphql/server/schemas/messages/index.js new file mode 100644 index 000000000000..438930fe8698 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/index.js @@ -0,0 +1,38 @@ +import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; + +// queries +import * as messages from './messages'; +// mutations +import * as sendMessage from './sendMessage'; +import * as editMessage from './editMessage'; +import * as deleteMessage from './deleteMessage'; +// types +import * as MessageType from './Message-type'; +import * as MessagesWithCursorType from './MessagesWithCursor-type'; +import * as MessageIdentifier from './MessageIdentifier-input'; +import * as ReactionType from './Reaction-type'; + +export const schema = mergeTypes([ + // queries + messages.schema, + // mutations + sendMessage.schema, + editMessage.schema, + deleteMessage.schema, + // types + MessageType.schema, + MessagesWithCursorType.schema, + MessageIdentifier.schema, + ReactionType.schema +]); + +export const resolvers = mergeResolvers([ + // queries + messages.resolver, + // mutations + sendMessage.resolver, + editMessage.resolver, + deleteMessage.resolver, + // types + MessageType.resolver +]); diff --git a/packages/rocketchat-graphql/server/schemas/messages/messages.js b/packages/rocketchat-graphql/server/schemas/messages/messages.js new file mode 100644 index 000000000000..84d0509f0fdc --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/messages.js @@ -0,0 +1,34 @@ +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; + +export const schema = ` + type Query { + messages(channelId: String): MessagesWithCursor + } +`; + +export const resolver = { + Query: { + messages: authenticated(AccountsServer, (root, args, { models }) => { + if (!args.channelId) { + console.error('messages query must be called with channelId'); + return null; + } + + const query = {}; + + if (args.channelId) { + query.rid = args.channelId; + } + + const messagesArray = models.Messages.find(query).fetch(); + const channel = models.Rooms.findOne(args.channelId); + + return { + cursor: 'CURSOR', + channel, + messagesArray + }; + }) + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js b/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js new file mode 100644 index 000000000000..ed675ce002d8 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js @@ -0,0 +1,27 @@ +/* global processWebhookMessage */ + +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; + +export const schema = ` + type Mutation { + sendMessage(channelId: String!, content: String!): Message + } +`; + +export const resolver = { + Mutation: { + sendMessage: authenticated(AccountsServer, (root, { channelId, content }, { user }) => { + const messageReturn = processWebhookMessage({ + roomId: channelId, + text: content + }, user)[0]; + + if (!messageReturn) { + throw new Error('Unknown error'); + } + + return messageReturn.message; + }) + } +}; From 373e8e56afcc51d41a1c94ee4c752e01c55f1d13 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Sat, 1 Jul 2017 15:20:05 +0100 Subject: [PATCH 05/42] Support nameFilter in channels query --- .../rocketchat-graphql/server/schemas/channels/channels.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/rocketchat-graphql/server/schemas/channels/channels.js b/packages/rocketchat-graphql/server/schemas/channels/channels.js index f53979adf037..4fa4dbfe224a 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channels.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channels.js @@ -25,6 +25,13 @@ export const resolver = { // Filter if (typeof args.filter !== 'undefined') { + // nameFilter + if (typeof args.filter.nameFilter !== undefined) { + query.name = { + $regex: new RegExp(args.filter.nameFilter, 'i') + }; + } + // sortBy if (args.filter.sortBy === 'NUMBER_OF_MESSAGES') { options.sort = { From 858a9c09ea33189d07b0efcc144ae22f187f8ee5 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 19 Jul 2017 17:03:30 +0100 Subject: [PATCH 06/42] WIP --- .meteor/packages | 1 + .meteor/versions | 1 + .../.npm/package/.gitignore | 1 + .../rocketchat-accounts/.npm/package/README | 7 + .../.npm/package/npm-shrinkwrap.json | 236 ++++++++++++++++++ packages/rocketchat-accounts/package.js | 23 ++ packages/rocketchat-accounts/server/config.js | 21 ++ packages/rocketchat-accounts/server/index.js | 7 + .../.npm/package/npm-shrinkwrap.json | 175 ++++++++++++- packages/rocketchat-graphql/package.js | 18 +- packages/rocketchat-graphql/server/api.js | 21 +- .../server/mocks/accounts/server.js | 2 +- packages/rocketchat-graphql/server/schema.js | 58 +---- .../schemas/accounts/LoginResult-type.js | 6 + .../server/schemas/accounts/index.js | 8 + .../accounts/loginWithServiceAccessToken.js | 32 +++ .../server/schemas/channels/Channel-type.js | 4 +- .../channels/ChannelNameAndDirect-input.js | 6 + .../server/schemas/channels/channels.js | 3 + .../server/schemas/channels/createChannel.js | 7 +- .../server/schemas/channels/hideChannel.js | 41 +++ .../server/schemas/channels/index.js | 24 +- .../server/schemas/channels/leaveChannel.js | 31 +++ .../server/schemas/messages/Message-type.js | 4 +- .../schemas/messages/addReactionToMessage.js | 24 ++ .../schemas/messages/chatMessageAdded.js | 29 +++ .../server/schemas/messages/index.js | 9 + .../server/schemas/messages/messages.js | 68 ++++- .../server/schemas/users/User-type.js | 36 +++ .../server/schemas/users/UserStatus-enum.js | 9 + .../server/schemas/users/index.js | 22 ++ .../server/schemas/users/setStatus.js | 22 ++ .../server/subscriptions.js | 3 + packages/rocketchat-lib/package.js | 1 + 34 files changed, 866 insertions(+), 94 deletions(-) create mode 100644 packages/rocketchat-accounts/.npm/package/.gitignore create mode 100644 packages/rocketchat-accounts/.npm/package/README create mode 100644 packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json create mode 100644 packages/rocketchat-accounts/package.js create mode 100644 packages/rocketchat-accounts/server/config.js create mode 100644 packages/rocketchat-accounts/server/index.js create mode 100644 packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.js create mode 100644 packages/rocketchat-graphql/server/schemas/accounts/index.js create mode 100644 packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/hideChannel.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.js create mode 100644 packages/rocketchat-graphql/server/schemas/users/User-type.js create mode 100644 packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.js create mode 100644 packages/rocketchat-graphql/server/schemas/users/index.js create mode 100644 packages/rocketchat-graphql/server/schemas/users/setStatus.js create mode 100644 packages/rocketchat-graphql/server/subscriptions.js diff --git a/.meteor/packages b/.meteor/packages index 53fb9389b819..c2f5c2bc98e6 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -38,6 +38,7 @@ tracker@1.1.3 rocketchat:2fa rocketchat:action-links +rocketchat:accounts rocketchat:analytics rocketchat:api rocketchat:assets diff --git a/.meteor/versions b/.meteor/versions index 5ceb7cee121a..253d100b0338 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -123,6 +123,7 @@ reactive-var@1.0.11 reload@1.1.11 retry@1.0.9 rocketchat:2fa@0.0.1 +rocketchat:accounts@0.0.1 rocketchat:action-links@0.0.1 rocketchat:analytics@0.0.2 rocketchat:api@0.0.1 diff --git a/packages/rocketchat-accounts/.npm/package/.gitignore b/packages/rocketchat-accounts/.npm/package/.gitignore new file mode 100644 index 000000000000..3c3629e647f5 --- /dev/null +++ b/packages/rocketchat-accounts/.npm/package/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/packages/rocketchat-accounts/.npm/package/README b/packages/rocketchat-accounts/.npm/package/README new file mode 100644 index 000000000000..3d492553a438 --- /dev/null +++ b/packages/rocketchat-accounts/.npm/package/README @@ -0,0 +1,7 @@ +This directory and the files immediately inside it are automatically generated +when you change this package's NPM dependencies. Commit the files in this +directory (npm-shrinkwrap.json, .gitignore, and this README) to source control +so that others run the same versions of sub-dependencies. + +You should NOT check in the node_modules directory that Meteor automatically +creates; if you are using git, the .gitignore file tells git to ignore it. diff --git a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json new file mode 100644 index 000000000000..0ff3f7f21819 --- /dev/null +++ b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json @@ -0,0 +1,236 @@ +{ + "dependencies": { + "addressparser": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/addressparser/-/addressparser-0.3.2.tgz", + "from": "addressparser@>=0.3.2 <0.4.0" + }, + "babel-polyfill": { + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.23.0.tgz", + "from": "babel-polyfill@>=6.23.0 <7.0.0" + }, + "babel-runtime": { + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.23.0.tgz", + "from": "babel-runtime@>=6.22.0 <7.0.0" + }, + "base64url": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz", + "from": "base64url@>=2.0.0 <3.0.0" + }, + "bcryptjs": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz", + "from": "bcryptjs@>=2.4.0 <3.0.0" + }, + "bson": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/bson/-/bson-1.0.4.tgz", + "from": "bson@>=1.0.4 <1.1.0" + }, + "buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "from": "buffer-equal-constant-time@1.0.1" + }, + "buffer-shims": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz", + "from": "buffer-shims@>=1.0.0 <1.1.0" + }, + "bufferjs": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/bufferjs/-/bufferjs-1.1.0.tgz", + "from": "bufferjs@1.1.0" + }, + "core-js": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.4.1.tgz", + "from": "core-js@>=2.4.0 <3.0.0" + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "from": "core-util-is@>=1.0.0 <1.1.0" + }, + "crypto": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/crypto/-/crypto-0.0.3.tgz", + "from": "crypto@>=0.0.3 <0.0.4" + }, + "ecdsa-sig-formatter": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz", + "from": "ecdsa-sig-formatter@1.0.9" + }, + "emailjs": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/emailjs/-/emailjs-1.0.11.tgz", + "from": "emailjs@>=1.0.8 <2.0.0" + }, + "encoding": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", + "from": "encoding@>=0.1.0 <0.2.0" + }, + "es6-promise": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.2.1.tgz", + "from": "es6-promise@3.2.1" + }, + "hoek": { + "version": "2.16.3", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", + "from": "hoek@>=2.0.0 <3.0.0" + }, + "iconv-lite": { + "version": "0.4.18", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.18.tgz", + "from": "iconv-lite@>=0.4.13 <0.5.0" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "from": "inherits@>=2.0.1 <2.1.0" + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "from": "isarray@>=1.0.0 <1.1.0" + }, + "isemail": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/isemail/-/isemail-1.2.0.tgz", + "from": "isemail@>=1.0.0 <2.0.0" + }, + "joi": { + "version": "6.10.1", + "resolved": "https://registry.npmjs.org/joi/-/joi-6.10.1.tgz", + "from": "joi@>=6.10.1 <7.0.0" + }, + "jsonwebtoken": { + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.1.tgz", + "from": "jsonwebtoken@>=7.2.1 <8.0.0" + }, + "jwa": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz", + "from": "jwa@>=1.1.4 <2.0.0" + }, + "jws": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.1.4.tgz", + "from": "jws@>=3.1.4 <4.0.0" + }, + "jwt-decode": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz", + "from": "jwt-decode@>=2.1.0 <3.0.0" + }, + "lodash": { + "version": "4.17.4", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", + "from": "lodash@>=4.16.4 <5.0.0" + }, + "lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "from": "lodash.once@>=4.0.0 <5.0.0" + }, + "mimelib": { + "version": "0.2.14", + "resolved": "https://registry.npmjs.org/mimelib/-/mimelib-0.2.14.tgz", + "from": "mimelib@0.2.14", + "dependencies": { + "addressparser": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/addressparser/-/addressparser-0.2.1.tgz", + "from": "addressparser@>=0.2.0 <0.3.0" + } + } + }, + "moment": { + "version": "2.11.2", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.11.2.tgz", + "from": "moment@2.11.2" + }, + "mongodb": { + "version": "2.2.30", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.30.tgz", + "from": "mongodb@>=2.2.22 <3.0.0" + }, + "mongodb-core": { + "version": "2.1.14", + "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.14.tgz", + "from": "mongodb-core@2.1.14" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "from": "ms@>=2.0.0 <3.0.0" + }, + "process-nextick-args": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", + "from": "process-nextick-args@>=1.0.6 <1.1.0" + }, + "readable-stream": { + "version": "2.2.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.7.tgz", + "from": "readable-stream@2.2.7" + }, + "regenerator-runtime": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", + "from": "regenerator-runtime@>=0.10.0 <0.11.0" + }, + "require_optional": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", + "from": "require_optional@>=1.0.0 <1.1.0" + }, + "resolve-from": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz", + "from": "resolve-from@>=2.0.0 <3.0.0" + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "from": "safe-buffer@>=5.0.1 <6.0.0" + }, + "semver": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz", + "from": "semver@>=5.1.0 <6.0.0" + }, + "starttls": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/starttls/-/starttls-1.0.1.tgz", + "from": "starttls@1.0.1" + }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "from": "string_decoder@>=1.0.0 <1.1.0" + }, + "topo": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/topo/-/topo-1.1.0.tgz", + "from": "topo@>=1.0.0 <2.0.0" + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "from": "util-deprecate@>=1.0.1 <1.1.0" + }, + "xtend": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", + "from": "xtend@>=4.0.1 <5.0.0" + } + } +} diff --git a/packages/rocketchat-accounts/package.js b/packages/rocketchat-accounts/package.js new file mode 100644 index 000000000000..ad3d2abb5687 --- /dev/null +++ b/packages/rocketchat-accounts/package.js @@ -0,0 +1,23 @@ +Package.describe({ + name: 'rocketchat:accounts', + version: '0.0.1', + summary: 'JS-Accounts integration', + git: '' +}); + +Package.onUse(function(api) { + api.use([ + 'underscore', + 'ecmascript' + ]); + + api.use('mongo', ['client', 'server']); + + api.mainModule('server/index.js', 'server'); +}); + +Npm.depends({ + '@accounts/server': '0.0.17', + '@accounts/mongo': '0.0.12-0', + '@accounts/meteor-adapter': '0.1.1' +}); diff --git a/packages/rocketchat-accounts/server/config.js b/packages/rocketchat-accounts/server/config.js new file mode 100644 index 000000000000..a9c215fdbd77 --- /dev/null +++ b/packages/rocketchat-accounts/server/config.js @@ -0,0 +1,21 @@ +import AccountsServer from '@accounts/server'; +import MongoAdapter from '@accounts/mongo'; +import { MongoInternals } from 'meteor/mongo'; +import { Meteor } from 'meteor/meteor'; + +Meteor.startup(() => { + const mongodb = MongoInternals.defaultRemoteCollectionDriver().mongo.db; + + const mongoAdapter = new MongoAdapter(mongodb); + + AccountsServer.config({ + tokenConfigs: { + accessToken: { + expiresIn: '3d' + }, + refreshToken: { + expiresIn: '30d' + } + } + }, mongoAdapter); +}); diff --git a/packages/rocketchat-accounts/server/index.js b/packages/rocketchat-accounts/server/index.js new file mode 100644 index 000000000000..7e25e6061c78 --- /dev/null +++ b/packages/rocketchat-accounts/server/index.js @@ -0,0 +1,7 @@ +import './config'; + +import AccountsServer from '@accounts/server'; + +export { + AccountsServer +}; diff --git a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json index 1c663c3f6914..9d5e2541f031 100644 --- a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json @@ -15,11 +15,36 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "from": "array-flatten@1.1.1" }, + "babel-runtime": { + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.23.0.tgz", + "from": "babel-runtime@>=6.23.0 <7.0.0" + }, + "backo2": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", + "from": "backo2@>=1.0.2 <2.0.0" + }, + "base64url": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz", + "from": "base64url@>=2.0.0 <3.0.0" + }, + "bcryptjs": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz", + "from": "bcryptjs@>=2.4.0 <3.0.0" + }, "body-parser": { "version": "1.17.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.17.2.tgz", "from": "body-parser@1.17.2" }, + "buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "from": "buffer-equal-constant-time@1.0.1" + }, "bytes": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz", @@ -45,19 +70,29 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "from": "cookie-signature@1.0.6" }, + "core-js": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.4.1.tgz", + "from": "core-js@>=2.4.0 <3.0.0" + }, "cors": { "version": "2.8.3", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.3.tgz", "from": "cors@2.8.3" }, + "crypto": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/crypto/-/crypto-0.0.3.tgz", + "from": "crypto@>=0.0.3 <0.0.4" + }, "debug": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.7.tgz", "from": "debug@2.6.7" }, "deepmerge": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-1.4.4.tgz", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-1.5.0.tgz", "from": "deepmerge@>=1.3.2 <2.0.0" }, "depd": { @@ -75,6 +110,11 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "from": "destroy@>=1.0.4 <1.1.0" }, + "ecdsa-sig-formatter": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz", + "from": "ecdsa-sig-formatter@1.0.9" + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -85,6 +125,11 @@ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz", "from": "encodeurl@>=1.0.1 <1.1.0" }, + "es6-promise": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.1.1.tgz", + "from": "es6-promise@>=4.0.5 <5.0.0" + }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -95,6 +140,11 @@ "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.0.tgz", "from": "etag@>=1.8.0 <1.9.0" }, + "eventemitter3": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz", + "from": "eventemitter3@>=2.0.3 <3.0.0" + }, "express": { "version": "4.15.3", "resolved": "https://registry.npmjs.org/express/-/express-4.15.3.tgz", @@ -140,6 +190,11 @@ "resolved": "https://registry.npmjs.org/graphql-server-module-graphiql/-/graphql-server-module-graphiql-0.9.0.tgz", "from": "graphql-server-module-graphiql@>=0.9.0 <0.10.0" }, + "graphql-subscriptions": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-0.4.4.tgz", + "from": "graphql-subscriptions@0.4.4" + }, "graphql-tag": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.4.2.tgz", @@ -150,6 +205,11 @@ "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-1.1.0.tgz", "from": "graphql-tools@1.1.0" }, + "hoek": { + "version": "2.16.3", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", + "from": "hoek@>=2.0.0 <3.0.0" + }, "http-errors": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.1.tgz", @@ -170,26 +230,76 @@ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.3.0.tgz", "from": "ipaddr.js@1.3.0" }, + "isemail": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/isemail/-/isemail-1.2.0.tgz", + "from": "isemail@>=1.0.0 <2.0.0" + }, "iterall": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.1.1.tgz", "from": "iterall@>=1.1.0 <2.0.0" }, + "joi": { + "version": "6.10.1", + "resolved": "https://registry.npmjs.org/joi/-/joi-6.10.1.tgz", + "from": "joi@>=6.10.1 <7.0.0" + }, "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", "from": "js-tokens@>=3.0.0 <4.0.0" }, + "jsonwebtoken": { + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.1.tgz", + "from": "jsonwebtoken@>=7.2.1 <8.0.0" + }, + "jwa": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz", + "from": "jwa@>=1.1.4 <2.0.0" + }, + "jws": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.1.4.tgz", + "from": "jws@>=3.1.4 <4.0.0" + }, + "jwt-decode": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz", + "from": "jwt-decode@>=2.1.0 <3.0.0" + }, "lodash": { "version": "4.17.4", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", - "from": "lodash@>=4.2.1 <5.0.0" + "from": "lodash@>=4.16.4 <5.0.0" }, "lodash-es": { "version": "4.17.4", "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.4.tgz", "from": "lodash-es@>=4.2.1 <5.0.0" }, + "lodash.assign": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz", + "from": "lodash.assign@>=4.2.0 <5.0.0" + }, + "lodash.isobject": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/lodash.isobject/-/lodash.isobject-3.0.2.tgz", + "from": "lodash.isobject@>=3.0.2 <4.0.0" + }, + "lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "from": "lodash.isstring@>=4.0.1 <5.0.0" + }, + "lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "from": "lodash.once@>=4.0.0 <5.0.0" + }, "loose-envify": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz", @@ -228,12 +338,17 @@ "mime-types": { "version": "2.1.15", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.15.tgz", - "from": "mime-types@>=2.1.11 <2.2.0" + "from": "mime-types@>=2.1.15 <2.2.0" + }, + "moment": { + "version": "2.18.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.18.1.tgz", + "from": "moment@>=2.0.0 <3.0.0" }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "from": "ms@2.0.0" + "from": "ms@>=2.0.0 <3.0.0" }, "negotiator": { "version": "0.6.1", @@ -281,10 +396,20 @@ "from": "raw-body@>=2.2.0 <2.3.0" }, "redux": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/redux/-/redux-3.7.1.tgz", + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/redux/-/redux-3.7.2.tgz", "from": "redux@>=3.4.0 <4.0.0" }, + "regenerator-runtime": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", + "from": "regenerator-runtime@>=0.10.0 <0.11.0" + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "from": "safe-buffer@>=5.0.1 <6.0.0" + }, "send": { "version": "0.15.3", "resolved": "https://registry.npmjs.org/send/-/send-0.15.3.tgz", @@ -303,22 +428,37 @@ "statuses": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", - "from": "statuses@>=1.3.1 <1.4.0" + "from": "statuses@>=1.3.1 <2.0.0" + }, + "subscriptions-transport-ws": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/subscriptions-transport-ws/-/subscriptions-transport-ws-0.8.1.tgz", + "from": "subscriptions-transport-ws@0.8.1" }, "symbol-observable": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.4.tgz", "from": "symbol-observable@>=1.0.2 <2.0.0" }, + "topo": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/topo/-/topo-1.1.0.tgz", + "from": "topo@>=1.0.0 <2.0.0" + }, "type-is": { "version": "1.6.15", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", "from": "type-is@>=1.6.15 <1.7.0" }, + "ultron": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.0.tgz", + "from": "ultron@>=1.1.0 <1.2.0" + }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "from": "unpipe@>=1.0.0 <1.1.0" + "from": "unpipe@1.0.0" }, "utils-merge": { "version": "1.0.0", @@ -339,6 +479,23 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", "from": "whatwg-fetch@>=2.0.0 <3.0.0" + }, + "ws": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-3.0.0.tgz", + "from": "ws@>=3.0.0 <4.0.0", + "dependencies": { + "safe-buffer": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.0.1.tgz", + "from": "safe-buffer@>=5.0.1 <5.1.0" + } + } + }, + "xtend": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", + "from": "xtend@>=4.0.1 <5.0.0" } } } diff --git a/packages/rocketchat-graphql/package.js b/packages/rocketchat-graphql/package.js index 3c29cdb70911..24f1b58779af 100644 --- a/packages/rocketchat-graphql/package.js +++ b/packages/rocketchat-graphql/package.js @@ -10,19 +10,23 @@ Package.onUse(function(api) { 'underscore', 'ecmascript', 'rocketchat:lib', - 'rocketchat:api' + 'rocketchat:api', + 'rocketchat:accounts' ]); - api.addFiles('server/api.js', 'server'); + api.mainModule('server/api.js', 'server'); }); Npm.depends({ + '@accounts/graphql-api': '0.1.1', 'apollo-client': '1.6.0', - cors: '2.8.3', - express: '4.15.3', - graphql: '0.10.3', + 'cors': '2.8.3', + 'body-parser': '1.17.2', + 'express': '4.15.3', + 'graphql': '0.10.3', 'graphql-server-express': '0.9.0', + 'graphql-subscriptions': '0.4.4', 'graphql-tools': '1.1.0', - 'body-parser': '1.17.2', - 'merge-graphql-schemas': '1.1.0' + 'merge-graphql-schemas': '1.1.0', + 'subscriptions-transport-ws': '0.8.1' }); diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index 040845247a44..069ada537a9b 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -1,4 +1,7 @@ import { graphqlExpress, graphiqlExpress } from 'graphql-server-express'; +import { JSAccountsContext as jsAccountsContext } from '@accounts/graphql-api'; +import { SubscriptionServer } from 'subscriptions-transport-ws'; +import { execute, subscribe } from 'graphql'; import bodyParser from 'body-parser'; import express from 'express'; import cors from 'cors'; @@ -16,11 +19,11 @@ graphQLServer.use(bodyParser.urlencoded({ extended: true })); graphQLServer.use( '/graphql', bodyParser.json(), - graphqlExpress(() => ({ + graphqlExpress(request => ({ schema: executableSchema, - context: { + context: Object.assign({ models: RocketChat.models - }, + }, jsAccountsContext(request)), formatError: e => ({ message: e.message, locations: e.locations, @@ -30,9 +33,19 @@ graphQLServer.use( }))); graphQLServer.use('/graphiql', graphiqlExpress({ - endpointURL: '/graphql' + endpointURL: '/graphql', + subscriptionsEndpoint: 'ws://localhost:3000/subscriptions' })); +new SubscriptionServer({ + schema: executableSchema, + execute, + subscribe +}, +{ + path: '/subscriptions', + server: WebApp.httpServer +}); // this binds the specified paths to the Express server running Apollo + GraphiQL WebApp.connectHandlers.use(graphQLServer); diff --git a/packages/rocketchat-graphql/server/mocks/accounts/server.js b/packages/rocketchat-graphql/server/mocks/accounts/server.js index 2d472b58e125..d44d2d09efae 100644 --- a/packages/rocketchat-graphql/server/mocks/accounts/server.js +++ b/packages/rocketchat-graphql/server/mocks/accounts/server.js @@ -7,7 +7,7 @@ const AccountsServer = { } // User credentials // mys:admin - return RocketChat.models.Users.findOneById('fnw4B4suFsTXf8rZq'); + return RocketChat.models.Users.findOne({username: 'mys'}); } }; diff --git a/packages/rocketchat-graphql/server/schema.js b/packages/rocketchat-graphql/server/schema.js index dd1fbb53097f..3ee5b41532fa 100644 --- a/packages/rocketchat-graphql/server/schema.js +++ b/packages/rocketchat-graphql/server/schema.js @@ -4,65 +4,23 @@ import { import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; -import { authenticated } from './mocks/accounts/graphql-api'; - -import AccountsServer from './mocks/accounts/server'; - -import { - property -} from './helpers/property'; - import * as channels from './schemas/channels'; import * as messages from './schemas/messages'; - -const rootSchema = ` - type Mutation { - setStatus(status: UserStatus!): Member - } - - enum UserStatus { - ONLINE - AWAY - BUSY - INVISIBLE - } - - type Member { - id: String! - name: String - # TODO: change to UserStatus - status: String - } -`; - -const rootResolvers = { - Mutation: { - setStatus: authenticated(AccountsServer, (root, { status }, { models, user }) => { - models.Users.update(user._id, { - $set: { - status: status.toLowerCase() - } - }); - - return models.Users.findOne(user._id); - }) - }, - Member: { - id: property('_id'), - status: ({status}) => status.toUpperCase() - } -}; +import * as accounts from './schemas/accounts'; +import * as users from './schemas/users'; const schema = mergeTypes([ - rootSchema, channels.schema, - messages.schema + messages.schema, + accounts.schema, + users.schema ]); const resolvers = mergeResolvers([ - rootResolvers, channels.resolvers, - messages.resolvers + messages.resolvers, + accounts.resolvers, + users.resolvers ]); export const executableSchema = makeExecutableSchema({ diff --git a/packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.js b/packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.js new file mode 100644 index 000000000000..4a0a7c8397b4 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.js @@ -0,0 +1,6 @@ +export const schema = ` + type LoginResult { + accessToken: String! + refreshToken: String! + } +`; diff --git a/packages/rocketchat-graphql/server/schemas/accounts/index.js b/packages/rocketchat-graphql/server/schemas/accounts/index.js new file mode 100644 index 000000000000..cf41ed398f04 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/accounts/index.js @@ -0,0 +1,8 @@ +import { createJSAccountsGraphQL } from '@accounts/graphql-api'; +import { AccountsServer } from 'meteor/rocketchat:accounts'; + +const accountsGraphQL = createJSAccountsGraphQL(AccountsServer); + +export const schema = accountsGraphQL.schema; + +export const resolvers = accountsGraphQL.extendWithResolvers({}); diff --git a/packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js b/packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js new file mode 100644 index 000000000000..26d95f49c0cf --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js @@ -0,0 +1,32 @@ +import AccountsServer from '../../mocks/accounts/server'; + +export const schema = ` + type Mutation { + loginWithServiceAccessToken(service: String!, accessToken: String!): LoginResult + } +`; + +export const resolver = { + Mutation: { + loginWithServiceAccessToken: async(root, { service, accessToken }) => { + try { + const userData = await oauthResolver.getUserDataFromService(accessToken, service); + const accountsServer = AccountsServer; + const user = await oauthResolver.getUserFromServiceUserData(service, userData); + + if (!user) { + return null; + } + + const loginResult = await accountsServer.loginWithUser(user); + + return { + refreshToken: loginResult.tokens.refreshToken, + accessToken: loginResult.tokens.accessToken + }; + } catch (e) { + console.error('Failed to login with service', e); + } + } + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js index 0d6dbac4512f..9d394c536aae 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js +++ b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js @@ -8,8 +8,8 @@ export const schema = ` description: String announcement: String topic: String - members: [Member] - owners: [Member] + members: [User] + owners: [User] numberOfMembers: Int numberOfMessages: Int readOnly: Boolean diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.js b/packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.js new file mode 100644 index 000000000000..f3bbda3125d1 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.js @@ -0,0 +1,6 @@ +export const schema = ` + input ChannelNameAndDirect { + name: String! + direct: Boolean! + } +`; diff --git a/packages/rocketchat-graphql/server/schemas/channels/channels.js b/packages/rocketchat-graphql/server/schemas/channels/channels.js index 4fa4dbfe224a..61a8535da41d 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channels.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channels.js @@ -50,6 +50,9 @@ export const resolver = { }; break; } + + // joinedChannels + // TODO: } return models.Rooms.find(query, options).fetch(); diff --git a/packages/rocketchat-graphql/server/schemas/channels/createChannel.js b/packages/rocketchat-graphql/server/schemas/channels/createChannel.js index 736afdaf00c0..e7fe0ce09a16 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/createChannel.js +++ b/packages/rocketchat-graphql/server/schemas/channels/createChannel.js @@ -5,7 +5,12 @@ import AccountsServer from '../../mocks/accounts/server'; export const schema = ` type Mutation { - createChannel(name: String!, private: Boolean = false, readOnly: Boolean = false, membersId: [String!]): Channel + createChannel( + name: String!, + private: Boolean = false, + readOnly: Boolean = false, + membersId: [String!] + ): Channel } `; diff --git a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js new file mode 100644 index 000000000000..95a8e0f0486f --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js @@ -0,0 +1,41 @@ +import { Meteor } from 'meteor/meteor'; + +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; + +export const schema = ` + type Mutation { + hideChannel(channelId: String!): Boolean + } +`; + +export const resolver = { + Mutation: { + hideChannel: authenticated(AccountsServer, (root, args, { models, user }) => { + const channel = models.Rooms.findOne({ + _id: args.channelId, + t: 'c' + }); + + if (!channel) { + throw new Error('error-room-not-found', 'The required "channelId" param provided does not match any channel'); + } + + const sub = models.Subscriptions.findOneByRoomIdAndUserId(channel._id, user._id); + + if (!sub) { + throw new Error(`The user/callee is not in the channel "${ channel.name }.`); + } + + if (!sub.open) { + throw new Error(`The channel, ${ channel.name }, is already closed to the sender`); + } + + Meteor.runAsUser(this.userId, () => { + Meteor.call('hideRoom', channel._id); + }); + + return true; + }) + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/index.js b/packages/rocketchat-graphql/server/schemas/channels/index.js index 25a1efcb4ebb..aa340a0030c5 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/index.js +++ b/packages/rocketchat-graphql/server/schemas/channels/index.js @@ -6,11 +6,14 @@ import * as channelByName from './channelByName'; import * as channelsByUser from './channelsByUser'; // mutations import * as createChannel from './createChannel'; +import * as leaveChannel from './leaveChannel'; +import * as hideChannel from './hideChannel'; // types -import * as channelType from './Channel-type'; -import * as channelSort from './ChannelSort-enum'; -import * as channelFilter from './ChannelFilter-input'; +import * as ChannelType from './Channel-type'; +import * as ChannelSort from './ChannelSort-enum'; +import * as ChannelFilter from './ChannelFilter-input'; import * as Privacy from './Privacy-enum'; +import * as ChannelNameAndDirect from './ChannelNameAndDirect-input'; export const schema = mergeTypes([ // queries @@ -19,11 +22,14 @@ export const schema = mergeTypes([ channelsByUser.schema, // mutations createChannel.schema, + leaveChannel.schema, + hideChannel.schema, // types - channelType.schema, - channelSort.schema, - channelFilter.schema, - Privacy.schema + ChannelType.schema, + ChannelSort.schema, + ChannelFilter.schema, + Privacy.schema, + ChannelNameAndDirect.schema ]); export const resolvers = mergeResolvers([ @@ -33,6 +39,8 @@ export const resolvers = mergeResolvers([ channelsByUser.resolver, // mutations createChannel.resolver, + leaveChannel.resolver, + hideChannel.resolver, // types - channelType.resolver + ChannelType.resolver ]); diff --git a/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js b/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js new file mode 100644 index 000000000000..d20c6042b0e9 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js @@ -0,0 +1,31 @@ +import { Meteor } from 'meteor/meteor'; + +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; + +export const schema = ` + type Mutation { + leaveChannel(channelId: String!): Boolean + } +`; + +export const resolver = { + Mutation: { + leaveChannel: authenticated(AccountsServer, (root, args, { models, user }) => { + const channel = models.Rooms.findOne({ + _id: args.channelId, + t: 'c' + }); + + if (!channel) { + throw new Error('error-room-not-found', 'The required "channelId" param provided does not match any channel'); + } + + Meteor.runAsUser(user._id, () => { + Meteor.call('leaveRoom', channel._id); + }); + + return true; + }) + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js index 9513feb12e10..3c6a1f0b34be 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js +++ b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js @@ -3,12 +3,12 @@ import { property } from '../../helpers/property'; export const schema = ` type Message { id: String - author: Member + author: User content: String channel: Channel creationTime: String fromServer: Boolean - userRef: [Member] + userRef: [User] channelRef: [Channel] reactions: [Reaction] # TODO diff --git a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js new file mode 100644 index 000000000000..89d020ea82b1 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js @@ -0,0 +1,24 @@ +import { Meteor } from 'meteor/meteor'; + +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; + +export const schema = ` + type Mutation { + addReactionToMassage(id: MessageIdentifier!, icon: String!): Message + } +`; + +export const resolver = { + Mutation: { + addReactionToMassage: authenticated(AccountsServer, (root, { id, icon }, { models, user }) => { + return new Promise((resolve) => { + Meteor.runAsUser(user._id, () => { + Meteor.call('setReaction', id.messageId, icon, () => { + resolve(models.findOne(id.messageId)); + }); + }); + }); + }) + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.js b/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.js new file mode 100644 index 000000000000..0f127c3c934f --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.js @@ -0,0 +1,29 @@ +import { withFilter } from 'graphql-subscriptions'; + +import { pubsub } from '../../subscriptions'; + +export const CHAT_MESSAGE_SUBSCRIPTION_TOPIC = 'CHAT_MESSAGE_ADDED'; + +export function publishMessage(message) { + pubsub.publish(CHAT_MESSAGE_SUBSCRIPTION_TOPIC, { chatMessageAdded: message }); +} + +export const schema = ` + type Subscription { + chatMessageAdded(channelId: String!): Message + } +`; + +export const resolver = { + Subscription: { + chatMessageAdded: { + subscribe: withFilter(() => pubsub.asyncIterator(CHAT_MESSAGE_SUBSCRIPTION_TOPIC), (payload, args) => { + return payload.chatMessageAdded.rid === args.channelId; + }) + } + } +}; + +RocketChat.callbacks.add('afterSaveMessage', (message) => { + publishMessage(message); +}, null, 'chatMessageAddedSubscription'); diff --git a/packages/rocketchat-graphql/server/schemas/messages/index.js b/packages/rocketchat-graphql/server/schemas/messages/index.js index 438930fe8698..fb9728b19815 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/index.js +++ b/packages/rocketchat-graphql/server/schemas/messages/index.js @@ -6,6 +6,9 @@ import * as messages from './messages'; import * as sendMessage from './sendMessage'; import * as editMessage from './editMessage'; import * as deleteMessage from './deleteMessage'; +import * as addReactionToMessage from './addReactionToMessage'; +// subscriptions +import * as chatMessageAdded from './chatMessageAdded'; // types import * as MessageType from './Message-type'; import * as MessagesWithCursorType from './MessagesWithCursor-type'; @@ -19,6 +22,9 @@ export const schema = mergeTypes([ sendMessage.schema, editMessage.schema, deleteMessage.schema, + addReactionToMessage.schema, + // subscriptions + chatMessageAdded.schema, // types MessageType.schema, MessagesWithCursorType.schema, @@ -33,6 +39,9 @@ export const resolvers = mergeResolvers([ sendMessage.resolver, editMessage.resolver, deleteMessage.resolver, + addReactionToMessage.resolver, + // subscriptions + chatMessageAdded.resolver, // types MessageType.resolver ]); diff --git a/packages/rocketchat-graphql/server/schemas/messages/messages.js b/packages/rocketchat-graphql/server/schemas/messages/messages.js index 84d0509f0fdc..a55aa09981b0 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/messages.js +++ b/packages/rocketchat-graphql/server/schemas/messages/messages.js @@ -3,29 +3,77 @@ import AccountsServer from '../../mocks/accounts/server'; export const schema = ` type Query { - messages(channelId: String): MessagesWithCursor + messages( + channelId: String, + channelDetails: ChannelNameAndDirect, + channelName: String, + cursor: String, + count: Int, + searchRegex: String + ): MessagesWithCursor } `; export const resolver = { Query: { messages: authenticated(AccountsServer, (root, args, { models }) => { - if (!args.channelId) { - console.error('messages query must be called with channelId'); + const messagesQuery = {}; + const messagesOptions = { + sort: { ts: 1 } + }; + const channelQuery = {}; + const isPagination = !!args.cursor || args.count > 0; + let cursor; + + if (args.channelId) { + // channelId + channelQuery._id = args.channelId; + } else if (args.channelDetails) { + // channelDetails + channelQuery.name = args.channelDetails.name; + channelQuery.t = args.channelDetails.direct === true ? 'd' : { $ne: 'd' }; + } else { + console.error('messages query must be called with channelId or channelDetails'); return null; } - const query = {}; + const channel = models.Rooms.findOne(channelQuery); + let messagesArray = []; - if (args.channelId) { - query.rid = args.channelId; - } + if (channel) { + + // cursor + if (isPagination && args.cursor) { + const cursorMsg = models.Messages.findOne(args.cursor, { fields: { ts: 1 } }); + messagesQuery.ts = { $gt: cursorMsg.ts }; + } - const messagesArray = models.Messages.find(query).fetch(); - const channel = models.Rooms.findOne(args.channelId); + // searchRegex + if (typeof args.searchRegex !== undefined) { + messagesQuery.msg = { + $regex: new RegExp(args.searchRegex, 'i') + }; + } + + // count + if (isPagination && args.count) { + messagesOptions.limit = args.count; + } + + const messages = models.Messages.find( + Object.assign({}, messagesQuery, { rid: channel._id }), + messagesOptions + ); + + messagesArray = messages.fetch(); + + if (isPagination) { + cursor = (messagesArray[messagesArray.length - 1] || {})._id; + } + } return { - cursor: 'CURSOR', + cursor, channel, messagesArray }; diff --git a/packages/rocketchat-graphql/server/schemas/users/User-type.js b/packages/rocketchat-graphql/server/schemas/users/User-type.js new file mode 100644 index 000000000000..76f75c194153 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/users/User-type.js @@ -0,0 +1,36 @@ +import { + property +} from '../../helpers/property'; + +export const schema = ` + extend type User { + status: UserStatus + avatar: String + name: String + lastLogin: String + channels: [Channel] + directMessages: [Channel] + } +`; + +export const resolver = { + User: { + id: property('_id'), + status: ({status}) => status.toUpperCase(), + avatar: ({ _id}, args, { models }) => { + const avatar = models.Avatars.findOne({ + userId: _id + }, { fields: { url: 1 }}); + + if (avatar) { + return avatar.url; + } + }, + channels: ({ _id }, args, { models }) => { + return models.Rooms.findBySubscriptionUserId(_id).fetch(); + }, + directMessages: ({ username }, args, { models }) => { + return models.Rooms.findByTypeContainingUsername('d', username).fetch(); + } + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.js b/packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.js new file mode 100644 index 000000000000..5e821bb5ee2a --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.js @@ -0,0 +1,9 @@ +export const schema = ` + enum UserStatus { + ONLINE + AWAY + BUSY + INVISIBLE + OFFLINE + } +`; diff --git a/packages/rocketchat-graphql/server/schemas/users/index.js b/packages/rocketchat-graphql/server/schemas/users/index.js new file mode 100644 index 000000000000..7647d5a5fdd6 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/users/index.js @@ -0,0 +1,22 @@ +import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; + +// mutations +import * as setStatus from './setStatus'; +// types +import * as UserType from './User-type'; +import * as UserStatus from './UserStatus-enum'; + +export const schema = mergeTypes([ + // mutations + setStatus.schema, + // types + UserType.schema, + UserStatus.schema +]); + +export const resolvers = mergeResolvers([ + // mutations + setStatus.resolver, + // types + UserType.resolver +]); diff --git a/packages/rocketchat-graphql/server/schemas/users/setStatus.js b/packages/rocketchat-graphql/server/schemas/users/setStatus.js new file mode 100644 index 000000000000..007ae3cf050e --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/users/setStatus.js @@ -0,0 +1,22 @@ +import { authenticated } from '../../mocks/accounts/graphql-api'; +import AccountsServer from '../../mocks/accounts/server'; + +export const schema = ` + type Mutation { + setStatus(status: UserStatus!): User + } +`; + +export const resolver = { + Mutation: { + setStatus: authenticated(AccountsServer, (root, { status }, { models, user }) => { + models.Users.update(user._id, { + $set: { + status: status.toLowerCase() + } + }); + + return models.Users.findOne(user._id); + }) + } +}; diff --git a/packages/rocketchat-graphql/server/subscriptions.js b/packages/rocketchat-graphql/server/subscriptions.js new file mode 100644 index 000000000000..d86d23f85d05 --- /dev/null +++ b/packages/rocketchat-graphql/server/subscriptions.js @@ -0,0 +1,3 @@ +import { PubSub } from 'graphql-subscriptions'; + +export const pubsub = new PubSub(); diff --git a/packages/rocketchat-lib/package.js b/packages/rocketchat-lib/package.js index 7be42499e08a..5eed6181d88b 100644 --- a/packages/rocketchat-lib/package.js +++ b/packages/rocketchat-lib/package.js @@ -34,6 +34,7 @@ Package.onUse(function(api) { api.use('matb33:collection-hooks'); api.use('service-configuration'); api.use('check'); + api.use('rocketchat:accounts'); api.use('rocketchat:i18n'); api.use('rocketchat:streamer'); api.use('rocketchat:version'); From 7bb4bfca525c6c1eefde09dcd6db9451af1e2922 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 20 Jul 2017 10:29:22 +0100 Subject: [PATCH 07/42] WIP --- packages/rocketchat-accounts/server/config.js | 8 ++++++-- packages/rocketchat-accounts/server/fix.js | 3 +++ packages/rocketchat-accounts/server/index.js | 1 + .../schemas/accounts/loginWithServiceAccessToken.js | 2 +- .../server/schemas/channels/channelByName.js | 5 +++-- .../server/schemas/channels/channels.js | 5 +++-- .../server/schemas/channels/channelsByUser.js | 5 +++-- .../server/schemas/channels/createChannel.js | 5 ++--- .../server/schemas/channels/hideChannel.js | 5 ++--- .../server/schemas/channels/leaveChannel.js | 5 ++--- .../server/schemas/messages/addReactionToMessage.js | 5 ++--- .../server/schemas/messages/deleteMessage.js | 5 ++--- .../server/schemas/messages/editMessage.js | 5 ++--- .../server/schemas/messages/messages.js | 4 ++-- .../server/schemas/messages/sendMessage.js | 4 ++-- .../rocketchat-graphql/server/schemas/users/setStatus.js | 4 ++-- 16 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 packages/rocketchat-accounts/server/fix.js diff --git a/packages/rocketchat-accounts/server/config.js b/packages/rocketchat-accounts/server/config.js index a9c215fdbd77..621db418d784 100644 --- a/packages/rocketchat-accounts/server/config.js +++ b/packages/rocketchat-accounts/server/config.js @@ -6,7 +6,10 @@ import { Meteor } from 'meteor/meteor'; Meteor.startup(() => { const mongodb = MongoInternals.defaultRemoteCollectionDriver().mongo.db; - const mongoAdapter = new MongoAdapter(mongodb); + const mongoAdapter = new MongoAdapter(mongodb, { + // XXX: UserId in RocketChat is a string(17) value + convertUserIdToMongoObjectId: false + }); AccountsServer.config({ tokenConfigs: { @@ -16,6 +19,7 @@ Meteor.startup(() => { refreshToken: { expiresIn: '30d' } - } + }, + passwordHashAlgorithm: 'sha256' }, mongoAdapter); }); diff --git a/packages/rocketchat-accounts/server/fix.js b/packages/rocketchat-accounts/server/fix.js new file mode 100644 index 000000000000..f1900a19c465 --- /dev/null +++ b/packages/rocketchat-accounts/server/fix.js @@ -0,0 +1,3 @@ +import regeneratorRuntime from 'babel-runtime/regenerator'; + +global.regeneratorRuntime = regeneratorRuntime; diff --git a/packages/rocketchat-accounts/server/index.js b/packages/rocketchat-accounts/server/index.js index 7e25e6061c78..a1fd2ccb053e 100644 --- a/packages/rocketchat-accounts/server/index.js +++ b/packages/rocketchat-accounts/server/index.js @@ -1,3 +1,4 @@ +import './fix'; import './config'; import AccountsServer from '@accounts/server'; diff --git a/packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js b/packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js index 26d95f49c0cf..0aeb4a1647f7 100644 --- a/packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js +++ b/packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js @@ -1,4 +1,4 @@ -import AccountsServer from '../../mocks/accounts/server'; +import AccountsServer from '@accounts/server'; export const schema = ` type Mutation { diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelByName.js b/packages/rocketchat-graphql/server/schemas/channels/channelByName.js index 9e0f0ca3c39c..de526a3659ed 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channelByName.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channelByName.js @@ -1,5 +1,6 @@ -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; + import { roomPublicFields } from './settings'; export const schema = ` diff --git a/packages/rocketchat-graphql/server/schemas/channels/channels.js b/packages/rocketchat-graphql/server/schemas/channels/channels.js index 61a8535da41d..8f50a32442dc 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channels.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channels.js @@ -1,5 +1,6 @@ -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; + import { roomPublicFields } from './settings'; export const schema = ` diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js index 98a888fe8970..188f715e2e8e 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js @@ -1,5 +1,6 @@ -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; + import { roomPublicFields } from './settings'; export const schema = ` diff --git a/packages/rocketchat-graphql/server/schemas/channels/createChannel.js b/packages/rocketchat-graphql/server/schemas/channels/createChannel.js index e7fe0ce09a16..a98db3e8529e 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/createChannel.js +++ b/packages/rocketchat-graphql/server/schemas/channels/createChannel.js @@ -1,7 +1,6 @@ import { Meteor } from 'meteor/meteor'; - -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; export const schema = ` type Mutation { diff --git a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js index 95a8e0f0486f..41b3a9ec48b5 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js +++ b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js @@ -1,7 +1,6 @@ import { Meteor } from 'meteor/meteor'; - -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; export const schema = ` type Mutation { diff --git a/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js b/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js index d20c6042b0e9..a4d7cf9cc97a 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js +++ b/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js @@ -1,7 +1,6 @@ import { Meteor } from 'meteor/meteor'; - -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; export const schema = ` type Mutation { diff --git a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js index 89d020ea82b1..b986dbc9b447 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js +++ b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js @@ -1,7 +1,6 @@ import { Meteor } from 'meteor/meteor'; - -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; export const schema = ` type Mutation { diff --git a/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js b/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js index 0b941817a8dd..332909ea9493 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js +++ b/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js @@ -1,7 +1,6 @@ import { Meteor } from 'meteor/meteor'; - -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; export const schema = ` type Mutation { diff --git a/packages/rocketchat-graphql/server/schemas/messages/editMessage.js b/packages/rocketchat-graphql/server/schemas/messages/editMessage.js index 6eacb619f51d..7e412a02076c 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/editMessage.js +++ b/packages/rocketchat-graphql/server/schemas/messages/editMessage.js @@ -1,7 +1,6 @@ import { Meteor } from 'meteor/meteor'; - -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; export const schema = ` type Mutation { diff --git a/packages/rocketchat-graphql/server/schemas/messages/messages.js b/packages/rocketchat-graphql/server/schemas/messages/messages.js index a55aa09981b0..d2ad849a2da1 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/messages.js +++ b/packages/rocketchat-graphql/server/schemas/messages/messages.js @@ -1,5 +1,5 @@ -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; export const schema = ` type Query { diff --git a/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js b/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js index ed675ce002d8..a7d40e13213b 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js +++ b/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js @@ -1,7 +1,7 @@ /* global processWebhookMessage */ -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; export const schema = ` type Mutation { diff --git a/packages/rocketchat-graphql/server/schemas/users/setStatus.js b/packages/rocketchat-graphql/server/schemas/users/setStatus.js index 007ae3cf050e..65311303b7a5 100644 --- a/packages/rocketchat-graphql/server/schemas/users/setStatus.js +++ b/packages/rocketchat-graphql/server/schemas/users/setStatus.js @@ -1,5 +1,5 @@ -import { authenticated } from '../../mocks/accounts/graphql-api'; -import AccountsServer from '../../mocks/accounts/server'; +import { authenticated } from '@accounts/graphql-api'; +import AccountsServer from '@accounts/server'; export const schema = ` type Mutation { From a75b31212a1638a4b7b505af3e25da224729d195 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Fri, 21 Jul 2017 13:32:35 +0100 Subject: [PATCH 08/42] WIP --- packages/rocketchat-accounts/package.js | 2 +- packages/rocketchat-accounts/server/index.js | 1 + packages/rocketchat-graphql/server/api.js | 31 ++++++++++-------- .../server/helpers/authenticated.js | 7 ++++ .../accounts/loginWithServiceAccessToken.js | 32 ------------------- .../server/schemas/channels/channelByName.js | 6 ++-- .../server/schemas/channels/channels.js | 6 ++-- .../server/schemas/channels/channelsByUser.js | 17 +++++----- .../server/schemas/channels/createChannel.js | 6 ++-- .../server/schemas/channels/hideChannel.js | 6 ++-- .../server/schemas/channels/leaveChannel.js | 6 ++-- .../schemas/messages/addReactionToMessage.js | 8 ++--- .../server/schemas/messages/deleteMessage.js | 6 ++-- .../server/schemas/messages/editMessage.js | 6 ++-- .../server/schemas/messages/messages.js | 5 ++- .../server/schemas/messages/sendMessage.js | 5 ++- .../server/schemas/users/User-type.js | 7 ++-- .../server/schemas/users/setStatus.js | 5 ++- 18 files changed, 69 insertions(+), 93 deletions(-) create mode 100644 packages/rocketchat-graphql/server/helpers/authenticated.js delete mode 100644 packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js diff --git a/packages/rocketchat-accounts/package.js b/packages/rocketchat-accounts/package.js index ad3d2abb5687..fd29a0c2ebae 100644 --- a/packages/rocketchat-accounts/package.js +++ b/packages/rocketchat-accounts/package.js @@ -17,7 +17,7 @@ Package.onUse(function(api) { }); Npm.depends({ - '@accounts/server': '0.0.17', + '@accounts/server': '0.0.18', '@accounts/mongo': '0.0.12-0', '@accounts/meteor-adapter': '0.1.1' }); diff --git a/packages/rocketchat-accounts/server/index.js b/packages/rocketchat-accounts/server/index.js index a1fd2ccb053e..87ec121feca8 100644 --- a/packages/rocketchat-accounts/server/index.js +++ b/packages/rocketchat-accounts/server/index.js @@ -3,6 +3,7 @@ import './config'; import AccountsServer from '@accounts/server'; + export { AccountsServer }; diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index 069ada537a9b..73aa590b4f07 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -2,11 +2,11 @@ import { graphqlExpress, graphiqlExpress } from 'graphql-server-express'; import { JSAccountsContext as jsAccountsContext } from '@accounts/graphql-api'; import { SubscriptionServer } from 'subscriptions-transport-ws'; import { execute, subscribe } from 'graphql'; +import { Meteor } from 'meteor/meteor'; +import { WebApp } from 'meteor/webapp'; import bodyParser from 'body-parser'; import express from 'express'; import cors from 'cors'; -import { Meteor } from 'meteor/meteor'; -import { WebApp } from 'meteor/webapp'; import { executableSchema } from './schema'; @@ -19,18 +19,21 @@ graphQLServer.use(bodyParser.urlencoded({ extended: true })); graphQLServer.use( '/graphql', bodyParser.json(), - graphqlExpress(request => ({ - schema: executableSchema, - context: Object.assign({ - models: RocketChat.models - }, jsAccountsContext(request)), - formatError: e => ({ - message: e.message, - locations: e.locations, - path: e.path - }), - debug: Meteor.isDevelopment - }))); + graphqlExpress(request => { + return { + schema: executableSchema, + context: Object.assign({ + models: RocketChat.models + }, jsAccountsContext(request)), + formatError: e => ({ + message: e.message, + locations: e.locations, + path: e.path + }), + debug: Meteor.isDevelopment + }; + }) +); graphQLServer.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql', diff --git a/packages/rocketchat-graphql/server/helpers/authenticated.js b/packages/rocketchat-graphql/server/helpers/authenticated.js new file mode 100644 index 000000000000..789101545ca1 --- /dev/null +++ b/packages/rocketchat-graphql/server/helpers/authenticated.js @@ -0,0 +1,7 @@ +import { Meteor } from 'meteor/meteor'; +import { AccountsServer } from 'meteor/rocketchat:accounts'; +import { authenticated as _authenticated } from '@accounts/graphql-api'; + +export const authenticated = (resolver) => { + return _authenticated(AccountsServer, Meteor.bindEnvironment(resolver), (error) => { throw error; }); +}; diff --git a/packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js b/packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js deleted file mode 100644 index 0aeb4a1647f7..000000000000 --- a/packages/rocketchat-graphql/server/schemas/accounts/loginWithServiceAccessToken.js +++ /dev/null @@ -1,32 +0,0 @@ -import AccountsServer from '@accounts/server'; - -export const schema = ` - type Mutation { - loginWithServiceAccessToken(service: String!, accessToken: String!): LoginResult - } -`; - -export const resolver = { - Mutation: { - loginWithServiceAccessToken: async(root, { service, accessToken }) => { - try { - const userData = await oauthResolver.getUserDataFromService(accessToken, service); - const accountsServer = AccountsServer; - const user = await oauthResolver.getUserFromServiceUserData(service, userData); - - if (!user) { - return null; - } - - const loginResult = await accountsServer.loginWithUser(user); - - return { - refreshToken: loginResult.tokens.refreshToken, - accessToken: loginResult.tokens.accessToken - }; - } catch (e) { - console.error('Failed to login with service', e); - } - } - } -}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelByName.js b/packages/rocketchat-graphql/server/schemas/channels/channelByName.js index de526a3659ed..213af845243c 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channelByName.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channelByName.js @@ -1,6 +1,4 @@ -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; - +import { authenticated } from '../../helpers/authenticated'; import { roomPublicFields } from './settings'; export const schema = ` @@ -11,7 +9,7 @@ export const schema = ` export const resolver = { Query: { - channelByName: authenticated(AccountsServer, (root, { name, isDirect }, { models }) => { + channelByName: authenticated((root, { name, isDirect }, { models }) => { const query = { name }; diff --git a/packages/rocketchat-graphql/server/schemas/channels/channels.js b/packages/rocketchat-graphql/server/schemas/channels/channels.js index 8f50a32442dc..f926ab80a1af 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channels.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channels.js @@ -1,6 +1,4 @@ -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; - +import { authenticated } from '../../helpers/authenticated'; import { roomPublicFields } from './settings'; export const schema = ` @@ -15,7 +13,7 @@ export const schema = ` export const resolver = { Query: { - channels: authenticated(AccountsServer, (root, args, { models }) => { + channels: authenticated((root, args, { models }) => { const query = {}; const options = { sort: { diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js index 188f715e2e8e..5651ef1a27b8 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js @@ -1,5 +1,4 @@ -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; +import { authenticated } from '../../helpers/authenticated'; import { roomPublicFields } from './settings'; @@ -11,7 +10,7 @@ export const schema = ` export const resolver = { Query: { - channelsByUser: authenticated(AccountsServer, (root, { userId }, { models }) => { + channelsByUser: authenticated((root, { userId }, { models }) => { const user = models.Users.findOneById(userId); if (!user) { @@ -19,16 +18,18 @@ export const resolver = { throw new Error('No user'); } - return models.Rooms.find({ - 'usernames': { - $in: user.username - } - }, { + // TODO: empty + const rooms = models.Rooms.findByContainingUsername(user.username, { sort: { name: 1 }, fields: roomPublicFields }).fetch(); + + console.log('user.username', user.username); + console.log('rooms', rooms); + + return rooms; }) } }; diff --git a/packages/rocketchat-graphql/server/schemas/channels/createChannel.js b/packages/rocketchat-graphql/server/schemas/channels/createChannel.js index a98db3e8529e..8d0274c8a311 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/createChannel.js +++ b/packages/rocketchat-graphql/server/schemas/channels/createChannel.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; + +import { authenticated } from '../../helpers/authenticated'; export const schema = ` type Mutation { @@ -15,7 +15,7 @@ export const schema = ` export const resolver = { Mutation: { - createChannel: authenticated(AccountsServer, (root, args, { models, user }) => { + createChannel: authenticated((root, args, { models, user }) => { if (!RocketChat.authz.hasPermission(user._id, 'create-c')) { return RocketChat.API.v1.unauthorized(); } diff --git a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js index 41b3a9ec48b5..3bb3627fe661 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js +++ b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; + +import { authenticated } from '../../helpers/authenticated'; export const schema = ` type Mutation { @@ -10,7 +10,7 @@ export const schema = ` export const resolver = { Mutation: { - hideChannel: authenticated(AccountsServer, (root, args, { models, user }) => { + hideChannel: authenticated((root, args, { models, user }) => { const channel = models.Rooms.findOne({ _id: args.channelId, t: 'c' diff --git a/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js b/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js index a4d7cf9cc97a..4eee709e2df4 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js +++ b/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; + +import { authenticated } from '../../helpers/authenticated'; export const schema = ` type Mutation { @@ -10,7 +10,7 @@ export const schema = ` export const resolver = { Mutation: { - leaveChannel: authenticated(AccountsServer, (root, args, { models, user }) => { + leaveChannel: authenticated((root, args, { models, user }) => { const channel = models.Rooms.findOne({ _id: args.channelId, t: 'c' diff --git a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js index b986dbc9b447..0e1104c541e8 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js +++ b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; + +import { authenticated } from '../../helpers/authenticated'; export const schema = ` type Mutation { @@ -10,11 +10,11 @@ export const schema = ` export const resolver = { Mutation: { - addReactionToMassage: authenticated(AccountsServer, (root, { id, icon }, { models, user }) => { + addReactionToMassage: authenticated((root, { id, icon }, { models, user }) => { return new Promise((resolve) => { Meteor.runAsUser(user._id, () => { Meteor.call('setReaction', id.messageId, icon, () => { - resolve(models.findOne(id.messageId)); + resolve(models.Messages.findOne(id.messageId)); }); }); }); diff --git a/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js b/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js index 332909ea9493..2f0aed85073b 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js +++ b/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; + +import { authenticated } from '../../helpers/authenticated'; export const schema = ` type Mutation { @@ -10,7 +10,7 @@ export const schema = ` export const resolver = { Mutation: { - deleteMessage: authenticated(AccountsServer, (root, { id }, { models, user }) => { + deleteMessage: authenticated((root, { id }, { models, user }) => { const msg = models.Messages.findOneById(id.messageId, { fields: { u: 1, rid: 1 }}); if (!msg) { diff --git a/packages/rocketchat-graphql/server/schemas/messages/editMessage.js b/packages/rocketchat-graphql/server/schemas/messages/editMessage.js index 7e412a02076c..1da2201d331e 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/editMessage.js +++ b/packages/rocketchat-graphql/server/schemas/messages/editMessage.js @@ -1,6 +1,6 @@ import { Meteor } from 'meteor/meteor'; -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; + +import { authenticated } from '../../helpers/authenticated'; export const schema = ` type Mutation { @@ -10,7 +10,7 @@ export const schema = ` export const resolver = { Mutation: { - editMessage: authenticated(AccountsServer, (root, { id, content }, { user, models }) => { + editMessage: authenticated((root, { id, content }, { user, models }) => { const msg = models.Messages.findOneById(id.messageId); //Ensure the message exists diff --git a/packages/rocketchat-graphql/server/schemas/messages/messages.js b/packages/rocketchat-graphql/server/schemas/messages/messages.js index d2ad849a2da1..7417470fdf0c 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/messages.js +++ b/packages/rocketchat-graphql/server/schemas/messages/messages.js @@ -1,5 +1,4 @@ -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; +import { authenticated } from '../../helpers/authenticated'; export const schema = ` type Query { @@ -16,7 +15,7 @@ export const schema = ` export const resolver = { Query: { - messages: authenticated(AccountsServer, (root, args, { models }) => { + messages: authenticated((root, args, { models }) => { const messagesQuery = {}; const messagesOptions = { sort: { ts: 1 } diff --git a/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js b/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js index a7d40e13213b..430460b72de8 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js +++ b/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js @@ -1,7 +1,6 @@ /* global processWebhookMessage */ -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; +import { authenticated } from '../../helpers/authenticated'; export const schema = ` type Mutation { @@ -11,7 +10,7 @@ export const schema = ` export const resolver = { Mutation: { - sendMessage: authenticated(AccountsServer, (root, { channelId, content }, { user }) => { + sendMessage: authenticated((root, { channelId, content }, { user }) => { const messageReturn = processWebhookMessage({ roomId: channelId, text: content diff --git a/packages/rocketchat-graphql/server/schemas/users/User-type.js b/packages/rocketchat-graphql/server/schemas/users/User-type.js index 76f75c194153..f6c0ff0d60e5 100644 --- a/packages/rocketchat-graphql/server/schemas/users/User-type.js +++ b/packages/rocketchat-graphql/server/schemas/users/User-type.js @@ -1,3 +1,5 @@ +import { Meteor } from 'meteor/meteor'; + import { property } from '../../helpers/property'; @@ -17,7 +19,7 @@ export const resolver = { User: { id: property('_id'), status: ({status}) => status.toUpperCase(), - avatar: ({ _id}, args, { models }) => { + avatar: Meteor.bindEnvironment(({ _id }, args, { models }) => { const avatar = models.Avatars.findOne({ userId: _id }, { fields: { url: 1 }}); @@ -25,7 +27,8 @@ export const resolver = { if (avatar) { return avatar.url; } - }, + return; + }), channels: ({ _id }, args, { models }) => { return models.Rooms.findBySubscriptionUserId(_id).fetch(); }, diff --git a/packages/rocketchat-graphql/server/schemas/users/setStatus.js b/packages/rocketchat-graphql/server/schemas/users/setStatus.js index 65311303b7a5..ca5362c0d945 100644 --- a/packages/rocketchat-graphql/server/schemas/users/setStatus.js +++ b/packages/rocketchat-graphql/server/schemas/users/setStatus.js @@ -1,5 +1,4 @@ -import { authenticated } from '@accounts/graphql-api'; -import AccountsServer from '@accounts/server'; +import { authenticated } from '../../helpers/authenticated'; export const schema = ` type Mutation { @@ -9,7 +8,7 @@ export const schema = ` export const resolver = { Mutation: { - setStatus: authenticated(AccountsServer, (root, { status }, { models, user }) => { + setStatus: authenticated((root, { status }, { models, user }) => { models.Users.update(user._id, { $set: { status: status.toLowerCase() From 9ea0ccef988b1cf1eb739b8b078fd2326fb4670b Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Fri, 21 Jul 2017 22:53:20 +0100 Subject: [PATCH 09/42] WIP --- packages/rocketchat-graphql/server/api.js | 4 +--- .../server/helpers/authenticated.js | 7 +++--- .../server/mocks/accounts/graphql-api.js | 23 ++++++++++++++++++- .../server/mocks/accounts/server.js | 5 ++-- .../server/schemas/channels/Channel-type.js | 8 +++---- .../server/schemas/channels/channelByName.js | 4 ++-- .../server/schemas/channels/channels.js | 4 ++-- .../server/schemas/channels/channelsByUser.js | 9 +++----- .../server/schemas/channels/createChannel.js | 4 ++-- .../server/schemas/channels/hideChannel.js | 6 ++--- .../server/schemas/channels/leaveChannel.js | 4 ++-- .../server/schemas/messages/Message-type.js | 16 ++++++------- .../schemas/messages/addReactionToMessage.js | 4 ++-- .../server/schemas/messages/deleteMessage.js | 4 ++-- .../server/schemas/messages/editMessage.js | 6 ++--- .../server/schemas/messages/messages.js | 10 ++++---- .../server/schemas/users/User-type.js | 16 ++++++------- .../server/schemas/users/setStatus.js | 6 ++--- 18 files changed, 77 insertions(+), 63 deletions(-) diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index 73aa590b4f07..7a82b6acec00 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -22,9 +22,7 @@ graphQLServer.use( graphqlExpress(request => { return { schema: executableSchema, - context: Object.assign({ - models: RocketChat.models - }, jsAccountsContext(request)), + context: jsAccountsContext(request), formatError: e => ({ message: e.message, locations: e.locations, diff --git a/packages/rocketchat-graphql/server/helpers/authenticated.js b/packages/rocketchat-graphql/server/helpers/authenticated.js index 789101545ca1..a0a39e676560 100644 --- a/packages/rocketchat-graphql/server/helpers/authenticated.js +++ b/packages/rocketchat-graphql/server/helpers/authenticated.js @@ -1,7 +1,8 @@ -import { Meteor } from 'meteor/meteor'; import { AccountsServer } from 'meteor/rocketchat:accounts'; -import { authenticated as _authenticated } from '@accounts/graphql-api'; +//import { authenticated as _authenticated } from '@accounts/graphql-api'; + +import { authenticated as _authenticated } from '../mocks/accounts/graphql-api'; export const authenticated = (resolver) => { - return _authenticated(AccountsServer, Meteor.bindEnvironment(resolver), (error) => { throw error; }); + return _authenticated(AccountsServer, resolver); }; diff --git a/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js b/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js index ac01fd1b681a..adbaaaa71d7e 100644 --- a/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js +++ b/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js @@ -1,9 +1,30 @@ -export const authenticated = (Accounts, func) => (async(root, args, context, info) => { +/*export const authenticated = (Accounts, func) => (async(root, args, context, info) => { const userObject = await Accounts.resumeSession(); if (userObject === null) { throw new Error('Invalid or expired token!'); } + return await func(root, args, Object.assign(context, { user: userObject }), info); +});*/ + +// Same as here: https://github.com/js-accounts/graphql/blob/master/packages/graphql-api/src/utils/authenticated-resolver.js +// except code below works +// It might be like that because of async/await, +// maybe Promise is not wrapped with Fiber +// See: https://github.com/meteor/meteor/blob/a362e20a37547362b581fed52f7171d022e83b62/packages/promise/server.js +export const authenticated = (Accounts, func) => (async(root, args, context, info) => { + const authToken = context.authToken; + + if (!authToken || authToken === '' || authToken === null) { + throw new Error('Unable to find authorization token in request'); + } + + const userObject = await Accounts.resumeSession(authToken); + + if (userObject === null) { + throw new Error('Invalid or expired token!'); + } + return await func(root, args, Object.assign(context, { user: userObject }), info); }); diff --git a/packages/rocketchat-graphql/server/mocks/accounts/server.js b/packages/rocketchat-graphql/server/mocks/accounts/server.js index d44d2d09efae..8bf64b3bccbf 100644 --- a/packages/rocketchat-graphql/server/mocks/accounts/server.js +++ b/packages/rocketchat-graphql/server/mocks/accounts/server.js @@ -1,14 +1,13 @@ const loggedOut = false; const AccountsServer = { - async resumeSession() { + resumeSession: (async() => { if (loggedOut) { throw new Error('User not found'); } // User credentials - // mys:admin return RocketChat.models.Users.findOne({username: 'mys'}); - } + }) }; export default AccountsServer; diff --git a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js index 9d394c536aae..8ae65ddb16aa 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js +++ b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js @@ -23,18 +23,18 @@ export const schema = ` export const resolver = { Channel: { id: property('_id'), - members: (root, args, { models }) => { + members: (root) => { return root.usernames.map( - username => models.Users.findOneByUsername(username) + username => RocketChat.models.Users.findOneByUsername(username) ); }, - owners: (root, args, { models }) => { + owners: (root) => { // there might be no owner if (!root.u) { return; } - return [models.Users.findOneByUsername(root.u.username)]; + return [RocketChat.models.Users.findOneByUsername(root.u.username)]; }, numberOfMembers: (root) => (root.usernames || []).length, numberOfMessages: property('msgs'), diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelByName.js b/packages/rocketchat-graphql/server/schemas/channels/channelByName.js index 213af845243c..32e6d1e44000 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channelByName.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channelByName.js @@ -9,7 +9,7 @@ export const schema = ` export const resolver = { Query: { - channelByName: authenticated((root, { name, isDirect }, { models }) => { + channelByName: authenticated((root, { name, isDirect }) => { const query = { name }; @@ -18,7 +18,7 @@ export const resolver = { query.c = 'd'; } - return models.Rooms.findOne(query, { + return RocketChat.models.Rooms.findOne(query, { fields: roomPublicFields }); }) diff --git a/packages/rocketchat-graphql/server/schemas/channels/channels.js b/packages/rocketchat-graphql/server/schemas/channels/channels.js index f926ab80a1af..c188819c96b3 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channels.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channels.js @@ -13,7 +13,7 @@ export const schema = ` export const resolver = { Query: { - channels: authenticated((root, args, { models }) => { + channels: authenticated((root, args) => { const query = {}; const options = { sort: { @@ -54,7 +54,7 @@ export const resolver = { // TODO: } - return models.Rooms.find(query, options).fetch(); + return RocketChat.models.Rooms.find(query, options).fetch(); }) } }; diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js index 5651ef1a27b8..b16e9f0c12fd 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js @@ -10,8 +10,8 @@ export const schema = ` export const resolver = { Query: { - channelsByUser: authenticated((root, { userId }, { models }) => { - const user = models.Users.findOneById(userId); + channelsByUser: authenticated((root, { userId }) => { + const user = RocketChat.models.Users.findOneById(userId); if (!user) { // TODO: @@ -19,16 +19,13 @@ export const resolver = { } // TODO: empty - const rooms = models.Rooms.findByContainingUsername(user.username, { + const rooms = RocketChat.models.Rooms.findByContainingUsername(user.username, { sort: { name: 1 }, fields: roomPublicFields }).fetch(); - console.log('user.username', user.username); - console.log('rooms', rooms); - return rooms; }) } diff --git a/packages/rocketchat-graphql/server/schemas/channels/createChannel.js b/packages/rocketchat-graphql/server/schemas/channels/createChannel.js index 8d0274c8a311..c87e88991767 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/createChannel.js +++ b/packages/rocketchat-graphql/server/schemas/channels/createChannel.js @@ -15,7 +15,7 @@ export const schema = ` export const resolver = { Mutation: { - createChannel: authenticated((root, args, { models, user }) => { + createChannel: authenticated((root, args, { user }) => { if (!RocketChat.authz.hasPermission(user._id, 'create-c')) { return RocketChat.API.v1.unauthorized(); } @@ -38,7 +38,7 @@ export const resolver = { id = Meteor.call('createChannel', args.name, args.membersId ? args.membersId : [], readOnly); }); - return models.Rooms.findOneById(id.rid, { fields: RocketChat.API.v1.defaultFieldsToExclude }); + return RocketChat.models.Rooms.findOneById(id.rid, { fields: RocketChat.API.v1.defaultFieldsToExclude }); }) } }; diff --git a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js index 3bb3627fe661..cab57e119468 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js +++ b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js @@ -10,8 +10,8 @@ export const schema = ` export const resolver = { Mutation: { - hideChannel: authenticated((root, args, { models, user }) => { - const channel = models.Rooms.findOne({ + hideChannel: authenticated((root, args, { user }) => { + const channel = RocketChat.models.Rooms.findOne({ _id: args.channelId, t: 'c' }); @@ -20,7 +20,7 @@ export const resolver = { throw new Error('error-room-not-found', 'The required "channelId" param provided does not match any channel'); } - const sub = models.Subscriptions.findOneByRoomIdAndUserId(channel._id, user._id); + const sub = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(channel._id, user._id); if (!sub) { throw new Error(`The user/callee is not in the channel "${ channel.name }.`); diff --git a/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js b/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js index 4eee709e2df4..141f1eba171f 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js +++ b/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js @@ -10,8 +10,8 @@ export const schema = ` export const resolver = { Mutation: { - leaveChannel: authenticated((root, args, { models, user }) => { - const channel = models.Rooms.findOne({ + leaveChannel: authenticated((root, args, { user }) => { + const channel = RocketChat.models.Rooms.findOne({ _id: args.channelId, t: 'c' }); diff --git a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js index 3c6a1f0b34be..3e52885e0ff2 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js +++ b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js @@ -21,19 +21,19 @@ export const resolver = { id: property('_id'), content: property('msg'), creationTime: property('ts'), - author: (root, args, { models }) => { - return models.Users.findOne(root.u._id); + author: (root) => { + return RocketChat.models.Users.findOne(root.u._id); }, - channel: (root, args, { models }) => { - return models.Rooms.findOne(root.rid); + channel: (root) => { + return RocketChat.models.Rooms.findOne(root.rid); }, fromServer: (root) => typeof root.t !== 'undefined', // on a message sent by user `true` otherwise `false` - channelRef: (root, args, { models }) => { + channelRef: (root) => { if (!root.channels) { return; } - return models.Rooms.find({ + return RocketChat.models.Rooms.find({ _id: { $in: root.channels.map(c => c._id) } @@ -43,12 +43,12 @@ export const resolver = { } }).fetch(); }, - userRef: (root, args, { models }) => { + userRef: (root) => { if (!root.mentions) { return; } - return models.Users.find({ + return RocketChat.models.Users.find({ _id: { $in: root.mentions.map(c => c._id) } diff --git a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js index 0e1104c541e8..2dc894969880 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js +++ b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js @@ -10,11 +10,11 @@ export const schema = ` export const resolver = { Mutation: { - addReactionToMassage: authenticated((root, { id, icon }, { models, user }) => { + addReactionToMassage: authenticated((root, { id, icon }, { user }) => { return new Promise((resolve) => { Meteor.runAsUser(user._id, () => { Meteor.call('setReaction', id.messageId, icon, () => { - resolve(models.Messages.findOne(id.messageId)); + resolve(RocketChat.models.Messages.findOne(id.messageId)); }); }); }); diff --git a/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js b/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js index 2f0aed85073b..91b3d0fa7e92 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js +++ b/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js @@ -10,8 +10,8 @@ export const schema = ` export const resolver = { Mutation: { - deleteMessage: authenticated((root, { id }, { models, user }) => { - const msg = models.Messages.findOneById(id.messageId, { fields: { u: 1, rid: 1 }}); + deleteMessage: authenticated((root, { id }, { user }) => { + const msg = RocketChat.models.Messages.findOneById(id.messageId, { fields: { u: 1, rid: 1 }}); if (!msg) { throw new Error(`No message found with the id of "${ id.messageId }".`); diff --git a/packages/rocketchat-graphql/server/schemas/messages/editMessage.js b/packages/rocketchat-graphql/server/schemas/messages/editMessage.js index 1da2201d331e..da1e1c8e850e 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/editMessage.js +++ b/packages/rocketchat-graphql/server/schemas/messages/editMessage.js @@ -10,8 +10,8 @@ export const schema = ` export const resolver = { Mutation: { - editMessage: authenticated((root, { id, content }, { user, models }) => { - const msg = models.Messages.findOneById(id.messageId); + editMessage: authenticated((root, { id, content }, { user }) => { + const msg = RocketChat.models.Messages.findOneById(id.messageId); //Ensure the message exists if (!msg) { @@ -27,7 +27,7 @@ export const resolver = { Meteor.call('updateMessage', { _id: msg._id, msg: content, rid: msg.rid }); }); - return models.Messages.findOneById(msg._id); + return RocketChat.models.Messages.findOneById(msg._id); }) } }; diff --git a/packages/rocketchat-graphql/server/schemas/messages/messages.js b/packages/rocketchat-graphql/server/schemas/messages/messages.js index 7417470fdf0c..ad8bb24cdfed 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/messages.js +++ b/packages/rocketchat-graphql/server/schemas/messages/messages.js @@ -15,7 +15,7 @@ export const schema = ` export const resolver = { Query: { - messages: authenticated((root, args, { models }) => { + messages: authenticated((root, args) => { const messagesQuery = {}; const messagesOptions = { sort: { ts: 1 } @@ -36,19 +36,19 @@ export const resolver = { return null; } - const channel = models.Rooms.findOne(channelQuery); + const channel = RocketChat.models.Rooms.findOne(channelQuery); let messagesArray = []; if (channel) { // cursor if (isPagination && args.cursor) { - const cursorMsg = models.Messages.findOne(args.cursor, { fields: { ts: 1 } }); + const cursorMsg = RocketChat.models.Messages.findOne(args.cursor, { fields: { ts: 1 } }); messagesQuery.ts = { $gt: cursorMsg.ts }; } // searchRegex - if (typeof args.searchRegex !== undefined) { + if (typeof args.searchRegex === 'string') { messagesQuery.msg = { $regex: new RegExp(args.searchRegex, 'i') }; @@ -59,7 +59,7 @@ export const resolver = { messagesOptions.limit = args.count; } - const messages = models.Messages.find( + const messages = RocketChat.models.Messages.find( Object.assign({}, messagesQuery, { rid: channel._id }), messagesOptions ); diff --git a/packages/rocketchat-graphql/server/schemas/users/User-type.js b/packages/rocketchat-graphql/server/schemas/users/User-type.js index f6c0ff0d60e5..34978665bcdb 100644 --- a/packages/rocketchat-graphql/server/schemas/users/User-type.js +++ b/packages/rocketchat-graphql/server/schemas/users/User-type.js @@ -1,5 +1,3 @@ -import { Meteor } from 'meteor/meteor'; - import { property } from '../../helpers/property'; @@ -19,8 +17,8 @@ export const resolver = { User: { id: property('_id'), status: ({status}) => status.toUpperCase(), - avatar: Meteor.bindEnvironment(({ _id }, args, { models }) => { - const avatar = models.Avatars.findOne({ + avatar: async({ _id }) => { + const avatar = RocketChat.models.Avatars.findOne({ userId: _id }, { fields: { url: 1 }}); @@ -28,12 +26,12 @@ export const resolver = { return avatar.url; } return; - }), - channels: ({ _id }, args, { models }) => { - return models.Rooms.findBySubscriptionUserId(_id).fetch(); }, - directMessages: ({ username }, args, { models }) => { - return models.Rooms.findByTypeContainingUsername('d', username).fetch(); + channels: ({ _id }) => { + return RocketChat.models.Rooms.findBySubscriptionUserId(_id).fetch(); + }, + directMessages: ({ username }) => { + return RocketChat.models.Rooms.findByTypeContainingUsername('d', username).fetch(); } } }; diff --git a/packages/rocketchat-graphql/server/schemas/users/setStatus.js b/packages/rocketchat-graphql/server/schemas/users/setStatus.js index ca5362c0d945..6c61f4675b77 100644 --- a/packages/rocketchat-graphql/server/schemas/users/setStatus.js +++ b/packages/rocketchat-graphql/server/schemas/users/setStatus.js @@ -8,14 +8,14 @@ export const schema = ` export const resolver = { Mutation: { - setStatus: authenticated((root, { status }, { models, user }) => { - models.Users.update(user._id, { + setStatus: authenticated((root, { status }, { user }) => { + RocketChat.models.Users.update(user._id, { $set: { status: status.toLowerCase() } }); - return models.Users.findOne(user._id); + return RocketChat.models.Users.findOne(user._id); }) } }; From 5f1bbc127b919953caed6b63a320c56380f14024 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Sat, 22 Jul 2017 12:49:43 +0100 Subject: [PATCH 10/42] Date to Float --- packages/rocketchat-graphql/server/helpers/dateToFloat.js | 5 +++++ .../server/schemas/messages/Message-type.js | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 packages/rocketchat-graphql/server/helpers/dateToFloat.js diff --git a/packages/rocketchat-graphql/server/helpers/dateToFloat.js b/packages/rocketchat-graphql/server/helpers/dateToFloat.js new file mode 100644 index 000000000000..faf206706f1b --- /dev/null +++ b/packages/rocketchat-graphql/server/helpers/dateToFloat.js @@ -0,0 +1,5 @@ +export function dateToFloat(date) { + if (date) { + return new Date(date).getTime(); + } +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js index 3e52885e0ff2..09204793acf7 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js +++ b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js @@ -1,4 +1,5 @@ import { property } from '../../helpers/property'; +import { dateToFloat } from '../../helpers/dateToFloat'; export const schema = ` type Message { @@ -6,7 +7,7 @@ export const schema = ` author: User content: String channel: Channel - creationTime: String + creationTime: Float fromServer: Boolean userRef: [User] channelRef: [Channel] @@ -20,7 +21,7 @@ export const resolver = { Message: { id: property('_id'), content: property('msg'), - creationTime: property('ts'), + creationTime: (root) => dateToFloat(root.ts), author: (root) => { return RocketChat.models.Users.findOne(root.u._id); }, From a036416feda5e4ae79aa956da2bc24912211d844 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Mon, 31 Jul 2017 19:13:56 +0200 Subject: [PATCH 11/42] Add directChannel query --- .../.npm/package/npm-shrinkwrap.json | 50 +++++++++---------- .../server/schemas/channels/channelByName.js | 11 ++-- .../server/schemas/channels/channelsByUser.js | 1 - .../server/schemas/channels/directChannel.js | 34 +++++++++++++ .../server/schemas/channels/hideChannel.js | 2 +- .../server/schemas/channels/index.js | 3 ++ 6 files changed, 67 insertions(+), 34 deletions(-) create mode 100644 packages/rocketchat-graphql/server/schemas/channels/directChannel.js diff --git a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json index 9d5e2541f031..5e620381c5c9 100644 --- a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json @@ -16,8 +16,8 @@ "from": "array-flatten@1.1.1" }, "babel-runtime": { - "version": "6.23.0", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.23.0.tgz", + "version": "6.25.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.25.0.tgz", "from": "babel-runtime@>=6.23.0 <7.0.0" }, "backo2": { @@ -96,8 +96,8 @@ "from": "deepmerge@>=1.3.2 <2.0.0" }, "depd": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.0.tgz", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", "from": "depd@>=1.1.0 <1.2.0" }, "deprecated-decorator": { @@ -213,7 +213,14 @@ "http-errors": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.1.tgz", - "from": "http-errors@>=1.6.1 <1.7.0" + "from": "http-errors@>=1.6.1 <1.7.0", + "dependencies": { + "depd": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.0.tgz", + "from": "depd@1.1.0" + } + } }, "iconv-lite": { "version": "0.4.15", @@ -226,9 +233,9 @@ "from": "inherits@2.0.3" }, "ipaddr.js": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.3.0.tgz", - "from": "ipaddr.js@1.3.0" + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.4.0.tgz", + "from": "ipaddr.js@1.4.0" }, "isemail": { "version": "1.2.0", @@ -331,13 +338,13 @@ "from": "mime@1.3.4" }, "mime-db": { - "version": "1.27.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz", - "from": "mime-db@>=1.27.0 <1.28.0" + "version": "1.29.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.29.0.tgz", + "from": "mime-db@>=1.29.0 <1.30.0" }, "mime-types": { - "version": "2.1.15", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.15.tgz", + "version": "2.1.16", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.16.tgz", "from": "mime-types@>=2.1.15 <2.2.0" }, "moment": { @@ -376,8 +383,8 @@ "from": "path-to-regexp@0.1.7" }, "proxy-addr": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.4.tgz", + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.5.tgz", "from": "proxy-addr@>=1.1.4 <1.2.0" }, "qs": { @@ -481,16 +488,9 @@ "from": "whatwg-fetch@>=2.0.0 <3.0.0" }, "ws": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-3.0.0.tgz", - "from": "ws@>=3.0.0 <4.0.0", - "dependencies": { - "safe-buffer": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.0.1.tgz", - "from": "safe-buffer@>=5.0.1 <5.1.0" - } - } + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-3.1.0.tgz", + "from": "ws@>=3.0.0 <4.0.0" }, "xtend": { "version": "4.0.1", diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelByName.js b/packages/rocketchat-graphql/server/schemas/channels/channelByName.js index 32e6d1e44000..63b70ddf360e 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channelByName.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channelByName.js @@ -3,21 +3,18 @@ import { roomPublicFields } from './settings'; export const schema = ` type Query { - channelByName(name: String!, isDirect: Boolean!): Channel + channelByName(name: String!): Channel } `; export const resolver = { Query: { - channelByName: authenticated((root, { name, isDirect }) => { + channelByName: authenticated((root, { name }) => { const query = { - name + name, + t: 'c' }; - if (isDirect === true) { - query.c = 'd'; - } - return RocketChat.models.Rooms.findOne(query, { fields: roomPublicFields }); diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js index b16e9f0c12fd..0784da1854a0 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js +++ b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js @@ -18,7 +18,6 @@ export const resolver = { throw new Error('No user'); } - // TODO: empty const rooms = RocketChat.models.Rooms.findByContainingUsername(user.username, { sort: { name: 1 diff --git a/packages/rocketchat-graphql/server/schemas/channels/directChannel.js b/packages/rocketchat-graphql/server/schemas/channels/directChannel.js new file mode 100644 index 000000000000..e2431551e811 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/directChannel.js @@ -0,0 +1,34 @@ +import { authenticated } from '../../helpers/authenticated'; +import { roomPublicFields } from './settings'; + +export const schema = ` + type Query { + directChannel(username: String, channelId: String): Channel + } +`; + +export const resolver = { + Query: { + directChannel: authenticated((root, { username, channelId }, { user }) => { + const query = { + t: 'd', + usernames: user.username + }; + + if (typeof username !== 'undefined') { + if (username === user.username) { + throw new Error('You cannot specify your username'); + } + query.usernames = { $all: [ user.username, username ] }; + } else if (typeof channelId !== 'undefined') { + query.id = channelId; + } else { + throw new Error('Use one of those fields: username, channelId'); + } + + return RocketChat.models.Rooms.findOne(query, { + fields: roomPublicFields + }); + }) + } +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js index cab57e119468..2904ca9dcd2f 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js +++ b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js @@ -30,7 +30,7 @@ export const resolver = { throw new Error(`The channel, ${ channel.name }, is already closed to the sender`); } - Meteor.runAsUser(this.userId, () => { + Meteor.runAsUser(user._id, () => { Meteor.call('hideRoom', channel._id); }); diff --git a/packages/rocketchat-graphql/server/schemas/channels/index.js b/packages/rocketchat-graphql/server/schemas/channels/index.js index aa340a0030c5..063e9da41804 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/index.js +++ b/packages/rocketchat-graphql/server/schemas/channels/index.js @@ -3,6 +3,7 @@ import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; // queries import * as channels from './channels'; import * as channelByName from './channelByName'; +import * as directChannel from './directChannel'; import * as channelsByUser from './channelsByUser'; // mutations import * as createChannel from './createChannel'; @@ -19,6 +20,7 @@ export const schema = mergeTypes([ // queries channels.schema, channelByName.schema, + directChannel.schema, channelsByUser.schema, // mutations createChannel.schema, @@ -36,6 +38,7 @@ export const resolvers = mergeResolvers([ // queries channels.resolver, channelByName.resolver, + directChannel.resolver, channelsByUser.resolver, // mutations createChannel.resolver, From 0ac6e21c5729674e52acd5dbd0f77b7c558888b6 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 1 Aug 2017 16:07:48 +0200 Subject: [PATCH 12/42] Expose username as name of direct channel --- .../server/schemas/channels/Channel-type.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js index 8ae65ddb16aa..b980acad0f7b 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js +++ b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js @@ -23,6 +23,13 @@ export const schema = ` export const resolver = { Channel: { id: property('_id'), + name: (root, args, { user }) => { + if (root.t === 'd') { + return root.usernames.find(u => u !== user.username); + } + + return root.name; + }, members: (root) => { return root.usernames.map( username => RocketChat.models.Users.findOneByUsername(username) From 0499617c603681eeb30ec54084cdbd8207d3c96b Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Fri, 4 Aug 2017 22:13:44 +0200 Subject: [PATCH 13/42] WIP: rocketchat:grant --- .meteor/packages | 1 + .meteor/versions | 3 +- .../.npm/package/npm-shrinkwrap.json | 8 +- .../rocketchat-grant/.npm/package/.gitignore | 1 + packages/rocketchat-grant/.npm/package/README | 7 + .../.npm/package/npm-shrinkwrap.json | 538 ++++++++++++++++++ packages/rocketchat-grant/README.md | 10 + packages/rocketchat-grant/package.js | 23 + packages/rocketchat-grant/server/grant.js | 62 ++ packages/rocketchat-grant/server/index.js | 53 ++ packages/rocketchat-grant/server/redirect.js | 71 +++ .../.npm/package/npm-shrinkwrap.json | 17 +- 12 files changed, 784 insertions(+), 10 deletions(-) create mode 100644 packages/rocketchat-grant/.npm/package/.gitignore create mode 100644 packages/rocketchat-grant/.npm/package/README create mode 100644 packages/rocketchat-grant/.npm/package/npm-shrinkwrap.json create mode 100644 packages/rocketchat-grant/README.md create mode 100644 packages/rocketchat-grant/package.js create mode 100644 packages/rocketchat-grant/server/grant.js create mode 100644 packages/rocketchat-grant/server/index.js create mode 100644 packages/rocketchat-grant/server/redirect.js diff --git a/.meteor/packages b/.meteor/packages index c2f5c2bc98e6..4231ae96279e 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -64,6 +64,7 @@ rocketchat:file-upload rocketchat:github-enterprise rocketchat:gitlab rocketchat:google-vision +rocketchat:grant rocketchat:graphql rocketchat:highlight-words rocketchat:iframe-login diff --git a/.meteor/versions b/.meteor/versions index 253d100b0338..3d64471778f4 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -42,7 +42,7 @@ ecmascript-runtime-server@0.4.1 edgee:slingshot@0.7.1 ejson@1.0.14 email@1.2.3 -emojione:emojione@2.2.6 +emojione:emojione@3.0.3 facebook-oauth@1.3.2 fastclick@1.0.13 francocatena:status@1.5.3 @@ -152,6 +152,7 @@ rocketchat:file-upload@0.0.1 rocketchat:github-enterprise@0.0.1 rocketchat:gitlab@0.0.1 rocketchat:google-vision@0.0.1 +rocketchat:grant@0.0.1 rocketchat:graphql@0.0.1 rocketchat:highlight-words@0.0.1 rocketchat:i18n@0.0.1 diff --git a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json index 0ff3f7f21819..f279fb73a316 100644 --- a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json @@ -11,8 +11,8 @@ "from": "babel-polyfill@>=6.23.0 <7.0.0" }, "babel-runtime": { - "version": "6.23.0", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.23.0.tgz", + "version": "6.25.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.25.0.tgz", "from": "babel-runtime@>=6.22.0 <7.0.0" }, "base64url": { @@ -203,8 +203,8 @@ "from": "safe-buffer@>=5.0.1 <6.0.0" }, "semver": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz", + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz", "from": "semver@>=5.1.0 <6.0.0" }, "starttls": { diff --git a/packages/rocketchat-grant/.npm/package/.gitignore b/packages/rocketchat-grant/.npm/package/.gitignore new file mode 100644 index 000000000000..3c3629e647f5 --- /dev/null +++ b/packages/rocketchat-grant/.npm/package/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/packages/rocketchat-grant/.npm/package/README b/packages/rocketchat-grant/.npm/package/README new file mode 100644 index 000000000000..3d492553a438 --- /dev/null +++ b/packages/rocketchat-grant/.npm/package/README @@ -0,0 +1,7 @@ +This directory and the files immediately inside it are automatically generated +when you change this package's NPM dependencies. Commit the files in this +directory (npm-shrinkwrap.json, .gitignore, and this README) to source control +so that others run the same versions of sub-dependencies. + +You should NOT check in the node_modules directory that Meteor automatically +creates; if you are using git, the .gitignore file tells git to ignore it. diff --git a/packages/rocketchat-grant/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-grant/.npm/package/npm-shrinkwrap.json new file mode 100644 index 000000000000..d824bf98528a --- /dev/null +++ b/packages/rocketchat-grant/.npm/package/npm-shrinkwrap.json @@ -0,0 +1,538 @@ +{ + "dependencies": { + "accepts": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.3.tgz", + "from": "accepts@>=1.3.3 <1.4.0" + }, + "ajv": { + "version": "4.11.8", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-4.11.8.tgz", + "from": "ajv@>=4.9.1 <5.0.0" + }, + "array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "from": "array-flatten@1.1.1" + }, + "asn1": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", + "from": "asn1@>=0.2.3 <0.3.0" + }, + "assert-plus": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.2.0.tgz", + "from": "assert-plus@>=0.2.0 <0.3.0" + }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "from": "asynckit@>=0.4.0 <0.5.0" + }, + "aws-sign2": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.6.0.tgz", + "from": "aws-sign2@>=0.6.0 <0.7.0" + }, + "aws4": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz", + "from": "aws4@>=1.2.1 <2.0.0" + }, + "bcrypt-pbkdf": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", + "from": "bcrypt-pbkdf@>=1.0.0 <2.0.0" + }, + "boom": { + "version": "2.10.1", + "resolved": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz", + "from": "boom@>=2.0.0 <3.0.0" + }, + "caseless": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "from": "caseless@>=0.12.0 <0.13.0" + }, + "co": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", + "from": "co@>=4.6.0 <5.0.0" + }, + "combined-stream": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", + "from": "combined-stream@>=1.0.5 <1.1.0" + }, + "content-disposition": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", + "from": "content-disposition@0.5.2" + }, + "content-type": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.2.tgz", + "from": "content-type@>=1.0.2 <1.1.0" + }, + "cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "from": "cookie@0.3.1" + }, + "cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "from": "cookie-signature@1.0.6" + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "from": "core-util-is@1.0.2" + }, + "crc": { + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/crc/-/crc-3.4.4.tgz", + "from": "crc@3.4.4" + }, + "cryptiles": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz", + "from": "cryptiles@>=2.0.0 <3.0.0" + }, + "dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "from": "dashdash@>=1.12.0 <2.0.0", + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "from": "assert-plus@>=1.0.0 <2.0.0" + } + } + }, + "debug": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.7.tgz", + "from": "debug@2.6.7" + }, + "deep-copy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/deep-copy/-/deep-copy-1.2.0.tgz", + "from": "deep-copy@>=1.2.0 <2.0.0" + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "from": "delayed-stream@>=1.0.0 <1.1.0" + }, + "depd": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", + "from": "depd@>=1.1.0 <1.2.0" + }, + "destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "from": "destroy@>=1.0.4 <1.1.0" + }, + "ecc-jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", + "from": "ecc-jsbn@>=0.1.1 <0.2.0" + }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "from": "ee-first@1.1.1" + }, + "encodeurl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz", + "from": "encodeurl@>=1.0.1 <1.1.0" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "from": "escape-html@>=1.0.3 <1.1.0" + }, + "etag": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.0.tgz", + "from": "etag@>=1.8.0 <1.9.0" + }, + "express": { + "version": "4.15.3", + "resolved": "https://registry.npmjs.org/express/-/express-4.15.3.tgz", + "from": "express@4.15.3" + }, + "express-session": { + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.15.4.tgz", + "from": "express-session@1.15.4", + "dependencies": { + "debug": { + "version": "2.6.8", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", + "from": "debug@2.6.8" + } + } + }, + "extend": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", + "from": "extend@>=3.0.0 <3.1.0" + }, + "extsprintf": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "from": "extsprintf@1.3.0" + }, + "finalhandler": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.3.tgz", + "from": "finalhandler@>=1.0.3 <1.1.0" + }, + "forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "from": "forever-agent@>=0.6.1 <0.7.0" + }, + "form-data": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.1.4.tgz", + "from": "form-data@>=2.1.1 <2.2.0" + }, + "forwarded": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.0.tgz", + "from": "forwarded@>=0.1.0 <0.2.0" + }, + "fresh": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.0.tgz", + "from": "fresh@0.5.0" + }, + "getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "from": "getpass@>=0.1.1 <0.2.0", + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "from": "assert-plus@>=1.0.0 <2.0.0" + } + } + }, + "grant": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/grant/-/grant-3.8.0.tgz", + "from": "grant@3.8.0" + }, + "grant-express": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/grant-express/-/grant-express-3.8.0.tgz", + "from": "grant-express@3.8.0" + }, + "har-schema": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-1.0.5.tgz", + "from": "har-schema@>=1.0.5 <2.0.0" + }, + "har-validator": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-4.2.1.tgz", + "from": "har-validator@>=4.2.1 <4.3.0" + }, + "hawk": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/hawk/-/hawk-3.1.3.tgz", + "from": "hawk@>=3.1.3 <3.2.0" + }, + "hoek": { + "version": "2.16.3", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", + "from": "hoek@>=2.0.0 <3.0.0" + }, + "http-errors": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.1.tgz", + "from": "http-errors@>=1.6.1 <1.7.0", + "dependencies": { + "depd": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.0.tgz", + "from": "depd@1.1.0" + } + } + }, + "http-signature": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.1.1.tgz", + "from": "http-signature@>=1.1.0 <1.2.0" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "from": "inherits@2.0.3" + }, + "ipaddr.js": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.4.0.tgz", + "from": "ipaddr.js@1.4.0" + }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "from": "is-typedarray@>=1.0.0 <1.1.0" + }, + "isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "from": "isstream@>=0.1.2 <0.2.0" + }, + "jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "from": "jsbn@>=0.1.0 <0.2.0" + }, + "json-schema": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", + "from": "json-schema@0.2.3" + }, + "json-stable-stringify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz", + "from": "json-stable-stringify@>=1.0.1 <2.0.0" + }, + "json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "from": "json-stringify-safe@>=5.0.1 <5.1.0" + }, + "jsonify": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", + "from": "jsonify@>=0.0.0 <0.1.0" + }, + "jsprim": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", + "from": "jsprim@>=1.2.2 <2.0.0", + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "from": "assert-plus@1.0.0" + } + } + }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "from": "media-typer@0.3.0" + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "from": "merge-descriptors@1.0.1" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "from": "methods@>=1.1.2 <1.2.0" + }, + "mime": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz", + "from": "mime@1.3.4" + }, + "mime-db": { + "version": "1.29.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.29.0.tgz", + "from": "mime-db@>=1.29.0 <1.30.0" + }, + "mime-types": { + "version": "2.1.16", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.16.tgz", + "from": "mime-types@>=2.1.11 <2.2.0" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "from": "ms@2.0.0" + }, + "negotiator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", + "from": "negotiator@0.6.1" + }, + "oauth-sign": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", + "from": "oauth-sign@>=0.8.1 <0.9.0" + }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "from": "on-finished@>=2.3.0 <2.4.0" + }, + "on-headers": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.1.tgz", + "from": "on-headers@>=1.0.1 <1.1.0" + }, + "parseurl": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.1.tgz", + "from": "parseurl@>=1.3.1 <1.4.0" + }, + "path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "from": "path-to-regexp@0.1.7" + }, + "performance-now": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-0.2.0.tgz", + "from": "performance-now@>=0.2.0 <0.3.0" + }, + "proxy-addr": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.5.tgz", + "from": "proxy-addr@>=1.1.4 <1.2.0" + }, + "punycode": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "from": "punycode@>=1.4.1 <2.0.0" + }, + "qs": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz", + "from": "qs@6.4.0" + }, + "random-bytes": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz", + "from": "random-bytes@>=1.0.0 <1.1.0" + }, + "range-parser": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", + "from": "range-parser@>=1.2.0 <1.3.0" + }, + "request": { + "version": "2.81.0", + "resolved": "https://registry.npmjs.org/request/-/request-2.81.0.tgz", + "from": "request@2.81.0" + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "from": "safe-buffer@>=5.0.1 <6.0.0" + }, + "send": { + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/send/-/send-0.15.3.tgz", + "from": "send@0.15.3" + }, + "serve-static": { + "version": "1.12.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.12.3.tgz", + "from": "serve-static@1.12.3" + }, + "setprototypeof": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", + "from": "setprototypeof@1.0.3" + }, + "sntp": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", + "from": "sntp@>=1.0.0 <2.0.0" + }, + "sshpk": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz", + "from": "sshpk@>=1.7.0 <2.0.0", + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "from": "assert-plus@>=1.0.0 <2.0.0" + } + } + }, + "statuses": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", + "from": "statuses@>=1.3.1 <1.4.0" + }, + "stringstream": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", + "from": "stringstream@>=0.0.4 <0.1.0" + }, + "tough-cookie": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.2.tgz", + "from": "tough-cookie@>=2.3.0 <2.4.0" + }, + "tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "from": "tunnel-agent@>=0.6.0 <0.7.0" + }, + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "from": "tweetnacl@>=0.14.0 <0.15.0" + }, + "type-is": { + "version": "1.6.15", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", + "from": "type-is@>=1.6.15 <1.7.0" + }, + "uid-safe": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", + "from": "uid-safe@>=2.1.4 <2.2.0" + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "from": "unpipe@>=1.0.0 <1.1.0" + }, + "utils-merge": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz", + "from": "utils-merge@1.0.0" + }, + "uuid": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", + "from": "uuid@>=3.0.0 <4.0.0" + }, + "vary": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.1.tgz", + "from": "vary@>=1.1.1 <1.2.0" + }, + "verror": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", + "from": "verror@1.10.0", + "dependencies": { + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "from": "assert-plus@>=1.0.0 <2.0.0" + } + } + } + } +} diff --git a/packages/rocketchat-grant/README.md b/packages/rocketchat-grant/README.md new file mode 100644 index 000000000000..b6b58a1c818f --- /dev/null +++ b/packages/rocketchat-grant/README.md @@ -0,0 +1,10 @@ +1. Settings should be the same as in OAuth section +1. Should be extendable (rocketchat:grant, rocketchat:grant-github etc) +1. Each package with provider should transform it's scope to user data so we can register a new user +1. rocketchat:grant-sub - to define sub configurations to allow for using external apps +1. rocketchat:grant should contain a middleware and startup fn with setup, that is already in rocketchat:oauth-external +1. in callback it would create and / or log in a user +1. without any specified sub configuration, it would redirect to localhost:3000 by default +1. with a specified sub configuration it would redirect to a path and add access_token to the URL + + diff --git a/packages/rocketchat-grant/package.js b/packages/rocketchat-grant/package.js new file mode 100644 index 000000000000..f6d63e698106 --- /dev/null +++ b/packages/rocketchat-grant/package.js @@ -0,0 +1,23 @@ +Package.describe({ + name: 'rocketchat:grant', + version: '0.0.1', + summary: 'OAuth2', + git: '' +}); + +Package.onUse(function(api) { + api.use([ + 'webapp', + 'mongo', + 'ecmascript', + 'rocketchat:lib' + ]); + + api.mainModule('server/index.js', 'server'); +}); + +Npm.depends({ + 'express': '4.15.3', + 'express-session': '1.15.4', + 'grant-express': '3.8.0' +}); diff --git a/packages/rocketchat-grant/server/grant.js b/packages/rocketchat-grant/server/grant.js new file mode 100644 index 000000000000..947d3d597c86 --- /dev/null +++ b/packages/rocketchat-grant/server/grant.js @@ -0,0 +1,62 @@ +export const path = '/_oauth_apps'; + +function generateCallback(serviceName) { + return `${ path }/${ serviceName }/callback`; +} + +function generateAppCallback(serviceName, appName) { + return generateCallback(`${ serviceName }/${ appName }`); +} + +function addProviders(config) { + const services = RocketChat.settings.get(/^(Accounts_OAuth_)[a-z0-9_]+$/i); + + services.forEach((service) => { + let serviceName = service.key.replace('Accounts_OAuth_', '').toLowerCase(); + + if (serviceName === 'meteor') { + serviceName = 'meteor-developer'; + } + + if (service.value === true) { + // TODO: scope + const data = { + key: RocketChat.settings.get(`${ service.key }_id`), + secret: RocketChat.settings.get(`${ service.key }_secret`), + callback: generateCallback(serviceName) + }; + + // TODO: create a space to set up OAuth services + if (serviceName === 'github') { + data.key = '96db2753350cfe8c8ae1'; + data.secret = '546317a561df5e3d350fca9b5500f270b54f3301'; + + console.log('PWA for GitHub'); + + // TODO: create a space to define Apps + data['pwa'] = { + callback: generateAppCallback(serviceName, 'pwa') + }; + } + + config[serviceName] = data; + } + }); + + return config; +} + +export function generateConfig() { + const config = { + server: { + protocol: 'http', + host: RocketChat.hostname, + path, + state: true + } + }; + + addProviders(config); + + return config; +} diff --git a/packages/rocketchat-grant/server/index.js b/packages/rocketchat-grant/server/index.js new file mode 100644 index 000000000000..c0cdba8bd7e1 --- /dev/null +++ b/packages/rocketchat-grant/server/index.js @@ -0,0 +1,53 @@ +/* +- localhost:3000/_oauth/facebook +- get the URI that this request comes from +- set it as redirectUrl +- do things +- add ?access_token= and ?service= to the URL +- redirect to it +*/ + +/*app.get(`${GRANT_PATH}/google/callback`, function (req, res) { + const accessToken = req.query.access_token; + res.redirect(`${STATIC_SERVER}/login?service=google&access_token=${accessToken}`); +});*/ + +import { WebApp } from 'meteor/webapp'; +import session from 'express-session'; +import Grant from 'grant-express'; +import fiber from 'fibers'; + +import { generateConfig, path } from './grant'; +import { middleware } from './redirect'; + +let grant; + +WebApp.connectHandlers.use(session({ + secret: 'grant', + resave: true, + saveUninitialized: true +})); + +// grant +WebApp.connectHandlers.use(path, (req, res, next) => { + if (grant) { + grant(req, res, next); + } else { + next(); + } +}); + +// callbacks +WebApp.connectHandlers.use((req, res, next) => { + fiber(() => { + middleware(req, res, next); + }).run(); +}); + +Meteor.startup(() => { + const config = generateConfig(); + + grant = new Grant(config); +}); + + diff --git a/packages/rocketchat-grant/server/redirect.js b/packages/rocketchat-grant/server/redirect.js new file mode 100644 index 000000000000..7b52a9b5fb28 --- /dev/null +++ b/packages/rocketchat-grant/server/redirect.js @@ -0,0 +1,71 @@ +function getEntry(req) { + let provider; + let app; + + const i = req.url.indexOf('?'); + let barePath; + + if (i === -1) { + barePath = req.url; + } else { + barePath = req.url.substring(0, i); + } + + const splitPath = barePath.split('/'); + + // Any non-oauth request will continue down the default + // middlewares. + if (splitPath[1] === '_oauth_apps') { + provider = splitPath[2]; + app = splitPath && splitPath[3] !== 'callback' ? splitPath[3] : null; + } + + return { + provider, + app + }; +} + +function getAccessToken(req) { + const i = req.url.indexOf('?'); + + if (i === -1) { + return; + } + + const barePath = req.url.substring(i + 1); + const splitPath = barePath.split('&'); + const token = splitPath.find(p => p.match(/access_token=[a-zA-Z0-9]+/)); + + if (token) { + return token.replace('access_token=', ''); + } +} + +export function middleware(req, res, next) { + const { + provider, + app + } = getEntry(req); + + if (!provider || !app) { + next(); + return; + } + + console.log('provider', provider); + console.log('app', app); + + // handle providers and apps + if (provider === 'github' && app === 'pwa') { + const token = getAccessToken(req); + console.log('token', token); + + // TODO: get redirect URL from settings + const redirectUrl = 'http://localhost:4200/login'; + + res.redirect(`${ redirectUrl }?service=${ provider }&access_token=${ token }`); + } + + next(); +} diff --git a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json index 5e620381c5c9..13032f7d6a0d 100644 --- a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json @@ -151,9 +151,16 @@ "from": "express@4.15.3" }, "finalhandler": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.3.tgz", - "from": "finalhandler@>=1.0.3 <1.1.0" + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.4.tgz", + "from": "finalhandler@>=1.0.3 <1.1.0", + "dependencies": { + "debug": { + "version": "2.6.8", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", + "from": "debug@2.6.8" + } + } }, "forwarded": { "version": "0.1.0", @@ -258,8 +265,8 @@ "from": "js-tokens@>=3.0.0 <4.0.0" }, "jsonwebtoken": { - "version": "7.4.1", - "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.1.tgz", + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.2.tgz", "from": "jsonwebtoken@>=7.2.1 <8.0.0" }, "jwa": { From ebe18ed35f93d2cf389bcd8bbdf26e889b444353 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 9 Aug 2017 15:25:42 +0200 Subject: [PATCH 14/42] rocketchat-grant --- .meteor/packages | 3 + .meteor/versions | 3 + .../.npm/package/npm-shrinkwrap.json | 8 +- packages/rocketchat-grant-facebook/package.js | 16 +++ .../rocketchat-grant-facebook/server/index.js | 65 ++++++++++++ packages/rocketchat-grant-github/package.js | 16 +++ .../rocketchat-grant-github/server/index.js | 51 ++++++++++ packages/rocketchat-grant-google/package.js | 16 +++ .../rocketchat-grant-google/server/index.js | 43 ++++++++ packages/rocketchat-grant/README.md | 2 - packages/rocketchat-grant/package.js | 4 +- .../rocketchat-grant/server/authenticate.js | 84 ++++++++++++++++ packages/rocketchat-grant/server/grant.js | 73 ++++++-------- packages/rocketchat-grant/server/index.js | 38 +++---- packages/rocketchat-grant/server/providers.js | 42 ++++++++ packages/rocketchat-grant/server/redirect.js | 99 ++++++++----------- packages/rocketchat-grant/server/routes.js | 48 +++++++++ packages/rocketchat-grant/server/settings.js | 42 ++++++++ packages/rocketchat-grant/server/storage.js | 33 +++++++ .../.npm/package/npm-shrinkwrap.json | 17 +--- packages/rocketchat-graphql/package.js | 1 + .../schemas/accounts/OauthProvider-type.js | 5 + .../server/schemas/accounts/index.js | 17 +++- .../server/schemas/accounts/oauthProviders.js | 41 ++++++++ server/configuration/grant.js | 27 +++++ 25 files changed, 653 insertions(+), 141 deletions(-) create mode 100644 packages/rocketchat-grant-facebook/package.js create mode 100644 packages/rocketchat-grant-facebook/server/index.js create mode 100644 packages/rocketchat-grant-github/package.js create mode 100644 packages/rocketchat-grant-github/server/index.js create mode 100644 packages/rocketchat-grant-google/package.js create mode 100644 packages/rocketchat-grant-google/server/index.js create mode 100644 packages/rocketchat-grant/server/authenticate.js create mode 100644 packages/rocketchat-grant/server/providers.js create mode 100644 packages/rocketchat-grant/server/routes.js create mode 100644 packages/rocketchat-grant/server/settings.js create mode 100644 packages/rocketchat-grant/server/storage.js create mode 100644 packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.js create mode 100644 packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.js create mode 100644 server/configuration/grant.js diff --git a/.meteor/packages b/.meteor/packages index 4231ae96279e..610aee81c3d2 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -65,6 +65,9 @@ rocketchat:github-enterprise rocketchat:gitlab rocketchat:google-vision rocketchat:grant +rocketchat:grant-facebook +rocketchat:grant-github +rocketchat:grant-google rocketchat:graphql rocketchat:highlight-words rocketchat:iframe-login diff --git a/.meteor/versions b/.meteor/versions index 3d64471778f4..e178545da53a 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -153,6 +153,9 @@ rocketchat:github-enterprise@0.0.1 rocketchat:gitlab@0.0.1 rocketchat:google-vision@0.0.1 rocketchat:grant@0.0.1 +rocketchat:grant-facebook@0.0.1 +rocketchat:grant-github@0.0.1 +rocketchat:grant-google@0.0.1 rocketchat:graphql@0.0.1 rocketchat:highlight-words@0.0.1 rocketchat:i18n@0.0.1 diff --git a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json index f279fb73a316..548e1696bac6 100644 --- a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json @@ -46,8 +46,8 @@ "from": "bufferjs@1.1.0" }, "core-js": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.4.1.tgz", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.0.tgz", "from": "core-js@>=2.4.0 <3.0.0" }, "core-util-is": { @@ -111,8 +111,8 @@ "from": "joi@>=6.10.1 <7.0.0" }, "jsonwebtoken": { - "version": "7.4.1", - "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.1.tgz", + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.2.tgz", "from": "jsonwebtoken@>=7.2.1 <8.0.0" }, "jwa": { diff --git a/packages/rocketchat-grant-facebook/package.js b/packages/rocketchat-grant-facebook/package.js new file mode 100644 index 000000000000..ad67058dde82 --- /dev/null +++ b/packages/rocketchat-grant-facebook/package.js @@ -0,0 +1,16 @@ +Package.describe({ + name: 'rocketchat:grant-facebook', + version: '0.0.1', + summary: 'Provides Facebook to rocketchat:grant', + git: '' +}); + +Package.onUse(function(api) { + api.use([ + 'ecmascript', + 'http', + 'rocketchat:grant' + ]); + + api.mainModule('server/index.js', 'server'); +}); diff --git a/packages/rocketchat-grant-facebook/server/index.js b/packages/rocketchat-grant-facebook/server/index.js new file mode 100644 index 000000000000..882ef18ac129 --- /dev/null +++ b/packages/rocketchat-grant-facebook/server/index.js @@ -0,0 +1,65 @@ +import { Providers } from 'meteor/rocketchat:grant'; +import { HTTP } from 'meteor/http'; + +const userAgent = 'Meteor'; +const version = 'v2.10'; + +function getIdentity(accessToken, fields) { + try { + return HTTP.get( + `https://graph.facebook.com/${ version }/me`, { + headers: { 'User-Agent': userAgent }, + params: { + access_token: accessToken, + fields: fields.join(',') + } + }).data; + } catch (err) { + console.log('err', err); + throw Object.assign( + new Error(`Failed to fetch identity from Facebook. ${ err.message }`), + { response: err.response } + ); + } +} + +function getPicture(accessToken) { + try { + return HTTP.get( + `https://graph.facebook.com/${ version }/me/picture`, { + headers: { 'User-Agent': userAgent }, + params: { + redirect: false, + height: 200, + width: 200, + type: 'normal', + access_token: accessToken + } + }).data; + } catch (err) { + throw Object.assign( + new Error(`Failed to fetch profile picture from Facebook. ${ err.message }`), + { response: err.response } + ); + } +} + +export function getUser(accessToken) { + const whitelisted = ['id', 'email', 'name', 'first_name', 'last_name']; + const identity = getIdentity(accessToken, whitelisted); + const avatar = getPicture(accessToken); + const username = identity.name.toLowerCase().replace(' ', '.'); + + return { + id: identity.id, + email: identity.email, + username, + profile: { + name: `${ identity.first_name } ${ identity.last_name }`, + avatar: avatar.data.url + } + }; +} + +// Register Facebook OAuth +Providers.register('facebook', { scope: ['public_profile', 'email'] }, getUser); diff --git a/packages/rocketchat-grant-github/package.js b/packages/rocketchat-grant-github/package.js new file mode 100644 index 000000000000..0e3ce2d86198 --- /dev/null +++ b/packages/rocketchat-grant-github/package.js @@ -0,0 +1,16 @@ +Package.describe({ + name: 'rocketchat:grant-github', + version: '0.0.1', + summary: 'Provides GitHub to rocketchat:grant', + git: '' +}); + +Package.onUse(function(api) { + api.use([ + 'ecmascript', + 'http', + 'rocketchat:grant' + ]); + + api.mainModule('server/index.js', 'server'); +}); diff --git a/packages/rocketchat-grant-github/server/index.js b/packages/rocketchat-grant-github/server/index.js new file mode 100644 index 000000000000..4359fe07754b --- /dev/null +++ b/packages/rocketchat-grant-github/server/index.js @@ -0,0 +1,51 @@ +import { Providers } from 'meteor/rocketchat:grant'; +import { HTTP } from 'meteor/http'; + +const userAgent = 'Meteor'; + +function getIdentity(accessToken) { + try { + return HTTP.get( + 'https://api.github.com/user', { + headers: { 'User-Agent': userAgent }, // http://developer.github.com/v3/#user-agent-required + params: { access_token: accessToken } + }).data; + } catch (err) { + throw Object.assign( + new Error(`Failed to fetch identity from Github. ${ err.message }`), + { response: err.response } + ); + } +} + +function getEmails(accessToken) { + try { + return HTTP.get( + 'https://api.github.com/user/emails', { + headers: { 'User-Agent': userAgent }, // http://developer.github.com/v3/#user-agent-required + params: { access_token: accessToken } + }).data; + } catch (err) { + return []; + } +} + +export function getUser(accessToken) { + const identity = getIdentity(accessToken); + const emails = getEmails(accessToken); + const primaryEmail = (emails || []).find(email => email.primary === true); + + return { + id: identity.id, + email: identity.email || (primaryEmail && primaryEmail.email) || '', + username: identity.login, + emails, + profile: { + name: identity.name, + avatar: identity.avatar_url + } + }; +} + +// Register GitHub OAuth +Providers.register('github', { scope: ['user', 'user:email'] }, getUser); diff --git a/packages/rocketchat-grant-google/package.js b/packages/rocketchat-grant-google/package.js new file mode 100644 index 000000000000..b0a538c44e57 --- /dev/null +++ b/packages/rocketchat-grant-google/package.js @@ -0,0 +1,16 @@ +Package.describe({ + name: 'rocketchat:grant-google', + version: '0.0.1', + summary: 'Provides Google to rocketchat:grant', + git: '' +}); + +Package.onUse(function(api) { + api.use([ + 'ecmascript', + 'http', + 'rocketchat:grant' + ]); + + api.mainModule('server/index.js', 'server'); +}); diff --git a/packages/rocketchat-grant-google/server/index.js b/packages/rocketchat-grant-google/server/index.js new file mode 100644 index 000000000000..5cc545c18cda --- /dev/null +++ b/packages/rocketchat-grant-google/server/index.js @@ -0,0 +1,43 @@ +import { Providers } from 'meteor/rocketchat:grant'; +import { HTTP } from 'meteor/http'; + +const userAgent = 'Meteor'; + +function getIdentity(accessToken) { + try { + return HTTP.get( + 'https://www.googleapis.com/oauth2/v1/userinfo', { + headers: { 'User-Agent': userAgent }, + params: { + access_token: accessToken + } + }).data; + } catch (err) { + throw Object.assign( + new Error(`Failed to fetch identity from Google. ${ err.message }`), + { response: err.response } + ); + } +} + +export function getUser(accessToken) { + const whitelisted = [ + 'id', 'email', 'verified_email', 'name', + 'given_name', 'family_name', 'picture' + ]; + const identity = getIdentity(accessToken, whitelisted); + const username = `${ identity.given_name.toLowerCase() }.${ identity.family_name.toLowerCase() }`; + + return { + id: identity.id, + email: identity.email, + username, + profile: { + name: identity.name, + avatar: identity.picture + } + }; +} + +// Register Google OAuth +Providers.register('google', { scope: ['openid', 'email'] }, getUser); diff --git a/packages/rocketchat-grant/README.md b/packages/rocketchat-grant/README.md index b6b58a1c818f..c526711cf6c9 100644 --- a/packages/rocketchat-grant/README.md +++ b/packages/rocketchat-grant/README.md @@ -6,5 +6,3 @@ 1. in callback it would create and / or log in a user 1. without any specified sub configuration, it would redirect to localhost:3000 by default 1. with a specified sub configuration it would redirect to a path and add access_token to the URL - - diff --git a/packages/rocketchat-grant/package.js b/packages/rocketchat-grant/package.js index f6d63e698106..bec938b3cb22 100644 --- a/packages/rocketchat-grant/package.js +++ b/packages/rocketchat-grant/package.js @@ -9,8 +9,10 @@ Package.onUse(function(api) { api.use([ 'webapp', 'mongo', + 'check', 'ecmascript', - 'rocketchat:lib' + 'rocketchat:lib', + 'rocketchat:accounts' ]); api.mainModule('server/index.js', 'server'); diff --git a/packages/rocketchat-grant/server/authenticate.js b/packages/rocketchat-grant/server/authenticate.js new file mode 100644 index 000000000000..bf2512d1f1aa --- /dev/null +++ b/packages/rocketchat-grant/server/authenticate.js @@ -0,0 +1,84 @@ +import { AccountsServer } from 'meteor/rocketchat:accounts'; +import { Accounts } from 'meteor/accounts-base'; + +import Providers from './providers'; + +const findUserByOAuthId = (providerName, id) => { + return RocketChat.models.Users.findOne({ [`settings.profile.oauth.${ providerName }`]: id }); +}; + +const addOAuthIdToUserProfile = (user, providerName, providerId) => { + const profile = Object.assign({}, user.settings.profile, { + oauth: { + ...user.settings.profile.oauth, + [providerName]: providerId + } + }); + + RocketChat.models.Users.setProfile(user.id, profile); +}; + +function getAccessToken(req) { + const i = req.url.indexOf('?'); + + if (i === -1) { + return; + } + + const barePath = req.url.substring(i + 1); + const splitPath = barePath.split('&'); + const token = splitPath.find(p => p.match(/access_token=[a-zA-Z0-9]+/)); + + if (token) { + return token.replace('access_token=', ''); + } +} + +export async function authenticate(providerName, req) { + let tokens; + const accessToken = getAccessToken(req); + const provider = Providers.get(providerName); + + if (!provider) { + throw new Error(`Provider '${ providerName }' not found`); + } + + const userData = provider.getUser(accessToken); + + let user = findUserByOAuthId(providerName, userData.id); + + if (user) { + user.id = user._id; + } else { + user = RocketChat.models.Users.findOneByEmailAddress(userData.email); + if (user) { + user.id = user._id; + } + } + + if (user) { + addOAuthIdToUserProfile(user, providerName, userData.id); + + const loginResult = await AccountsServer.loginWithUser({ id: user.id }); + + tokens = loginResult.tokens; + } else { + const id = Accounts.createUser({ + email: userData.email + }); + + RocketChat.models.Users.setProfile(id, { + name: userData.profile.name, + avatar: userData.profile.avatar, + oauth: { + [providerName]: userData.id + } + }); + + const loginResult = await AccountsServer.loginWithUser({ id }); + + tokens = loginResult.tokens; + } + + return tokens; +} diff --git a/packages/rocketchat-grant/server/grant.js b/packages/rocketchat-grant/server/grant.js index 947d3d597c86..0f8890652909 100644 --- a/packages/rocketchat-grant/server/grant.js +++ b/packages/rocketchat-grant/server/grant.js @@ -1,62 +1,51 @@ -export const path = '/_oauth_apps'; - -function generateCallback(serviceName) { - return `${ path }/${ serviceName }/callback`; -} - -function generateAppCallback(serviceName, appName) { - return generateCallback(`${ serviceName }/${ appName }`); -} +import Providers from './providers'; +import Settings from './settings'; +import { path, generateCallback, generateAppCallback } from './routes'; function addProviders(config) { - const services = RocketChat.settings.get(/^(Accounts_OAuth_)[a-z0-9_]+$/i); - - services.forEach((service) => { - let serviceName = service.key.replace('Accounts_OAuth_', '').toLowerCase(); + Settings.forEach((settings, providerName) => { + if (settings.enabled === true) { + const registeredProvider = Providers.get(providerName); - if (serviceName === 'meteor') { - serviceName = 'meteor-developer'; - } + if (!registeredProvider) { + console.error(`No configuration for '${ providerName }' provider`); + } - if (service.value === true) { - // TODO: scope + // basic settings const data = { - key: RocketChat.settings.get(`${ service.key }_id`), - secret: RocketChat.settings.get(`${ service.key }_secret`), - callback: generateCallback(serviceName) + key: settings.key, + secret: settings.secret, + scope: registeredProvider.scope, + callback: generateCallback(providerName) }; - // TODO: create a space to set up OAuth services - if (serviceName === 'github') { - data.key = '96db2753350cfe8c8ae1'; - data.secret = '546317a561df5e3d350fca9b5500f270b54f3301'; - - console.log('PWA for GitHub'); - - // TODO: create a space to define Apps - data['pwa'] = { - callback: generateAppCallback(serviceName, 'pwa') + // set each app + Settings.apps.forEach((_, appName) => { + data[appName] = { + callback: generateAppCallback(providerName, appName) }; - } + }); - config[serviceName] = data; + config[providerName] = data; } }); - - return config; } +const config = {}; + export function generateConfig() { - const config = { - server: { - protocol: 'http', - host: RocketChat.hostname, - path, - state: true - } + config['server'] = { + protocol: 'http', + host: RocketChat.hostname, + path, + state: true }; addProviders(config); return config; } + +export function getConfig() { + return config; +} diff --git a/packages/rocketchat-grant/server/index.js b/packages/rocketchat-grant/server/index.js index c0cdba8bd7e1..fc06ae57ba3a 100644 --- a/packages/rocketchat-grant/server/index.js +++ b/packages/rocketchat-grant/server/index.js @@ -1,24 +1,13 @@ -/* -- localhost:3000/_oauth/facebook -- get the URI that this request comes from -- set it as redirectUrl -- do things -- add ?access_token= and ?service= to the URL -- redirect to it -*/ - -/*app.get(`${GRANT_PATH}/google/callback`, function (req, res) { - const accessToken = req.query.access_token; - res.redirect(`${STATIC_SERVER}/login?service=google&access_token=${accessToken}`); -});*/ - import { WebApp } from 'meteor/webapp'; import session from 'express-session'; import Grant from 'grant-express'; import fiber from 'fibers'; -import { generateConfig, path } from './grant'; -import { middleware } from './redirect'; +import { generateConfig } from './grant'; +import { path, generateCallback, generateAppCallback } from './routes'; +import { middleware as redirect } from './redirect'; +import Providers, { middleware as providers } from './providers'; +import Settings from './settings'; let grant; @@ -40,7 +29,14 @@ WebApp.connectHandlers.use(path, (req, res, next) => { // callbacks WebApp.connectHandlers.use((req, res, next) => { fiber(() => { - middleware(req, res, next); + redirect(req, res, next); + }).run(); +}); + +// providers +WebApp.connectHandlers.use((req, res, next) => { + fiber(() => { + providers(req, res, next); }).run(); }); @@ -50,4 +46,10 @@ Meteor.startup(() => { grant = new Grant(config); }); - +export { + path, + generateCallback, + generateAppCallback, + Providers, + Settings +}; diff --git a/packages/rocketchat-grant/server/providers.js b/packages/rocketchat-grant/server/providers.js new file mode 100644 index 000000000000..4b2aad10cee5 --- /dev/null +++ b/packages/rocketchat-grant/server/providers.js @@ -0,0 +1,42 @@ +import { check } from 'meteor/check'; + +import { Storage } from './storage'; +import { routes } from './routes'; + +class Providers extends Storage { + register(name, options, getUser) { + check(name, String); + check(options, { + // eslint-disable-next-line + scope: Match.OneOf(String, [String]) + }); + check(getUser, Function); + + this._add(name.toLowerCase(), { + scope: options.scope, + getUser + }); + } +} + +const providers = new Providers; + +export default providers; + +export function middleware(req, res, next) { + const route = routes.providers(req); + + if (route) { + const list = []; + + providers.forEach((_, name) => list.push(name)); + + // TODO: send a list of providers + res.end(JSON.stringify({ + data: list + })); + return; + } + + next(); +} diff --git a/packages/rocketchat-grant/server/redirect.js b/packages/rocketchat-grant/server/redirect.js index 7b52a9b5fb28..25faad1e1ca9 100644 --- a/packages/rocketchat-grant/server/redirect.js +++ b/packages/rocketchat-grant/server/redirect.js @@ -1,70 +1,49 @@ -function getEntry(req) { - let provider; - let app; +import { authenticate } from './authenticate'; +import Settings from './settings'; +import { routes } from './routes'; - const i = req.url.indexOf('?'); - let barePath; - - if (i === -1) { - barePath = req.url; - } else { - barePath = req.url.substring(0, i); - } - - const splitPath = barePath.split('/'); - - // Any non-oauth request will continue down the default - // middlewares. - if (splitPath[1] === '_oauth_apps') { - provider = splitPath[2]; - app = splitPath && splitPath[3] !== 'callback' ? splitPath[3] : null; - } - - return { - provider, - app - }; +function parseUrl(url, config) { + return url.replace(/\{[\ ]*(provider|accessToken|refreshToken|error)[\ ]*\}/g, (_, key) => config[key]); } -function getAccessToken(req) { - const i = req.url.indexOf('?'); +function getAppConfig(providerName, appName) { + const providerConfig = Settings.get(providerName); - if (i === -1) { - return; - } - - const barePath = req.url.substring(i + 1); - const splitPath = barePath.split('&'); - const token = splitPath.find(p => p.match(/access_token=[a-zA-Z0-9]+/)); - - if (token) { - return token.replace('access_token=', ''); + if (providerConfig) { + return Settings.apps.get(appName); } } -export function middleware(req, res, next) { - const { - provider, - app - } = getEntry(req); - - if (!provider || !app) { - next(); - return; - } - - console.log('provider', provider); - console.log('app', app); - - // handle providers and apps - if (provider === 'github' && app === 'pwa') { - const token = getAccessToken(req); - console.log('token', token); - - // TODO: get redirect URL from settings - const redirectUrl = 'http://localhost:4200/login'; - - res.redirect(`${ redirectUrl }?service=${ provider }&access_token=${ token }`); +export async function middleware(req, res, next) { + const route = routes.appCallback(req); + + // handle app callback + if (route) { + const config = { + provider: route.provider + }; + const appConfig = getAppConfig(route.provider, route.app); + + if (appConfig) { + const { + redirectUrl, + errorUrl + } = appConfig; + + try { + const tokens = await authenticate(route.provider, req); + + config.accessToken = tokens.accessToken; + config.refreshToken = tokens.refreshToken; + + res.redirect(parseUrl(redirectUrl, config)); + return; + } catch (error) { + config.error = error.message; + res.redirect(parseUrl(errorUrl, config)); + return; + } + } } next(); diff --git a/packages/rocketchat-grant/server/routes.js b/packages/rocketchat-grant/server/routes.js new file mode 100644 index 000000000000..041156f2abca --- /dev/null +++ b/packages/rocketchat-grant/server/routes.js @@ -0,0 +1,48 @@ +export const path = '/_oauth_apps'; + +export function generateCallback(providerName) { + return `${ path }/${ providerName }/callback`; +} + +export function generateAppCallback(providerName, appName) { + return generateCallback(`${ providerName }/${ appName }`); +} + +export function getPaths(req) { + const i = req.url.indexOf('?'); + let barePath; + + if (i === -1) { + barePath = req.url; + } else { + barePath = req.url.substring(0, i); + } + + const splitPath = barePath.split('/'); + + // Any non-oauth request will continue down the default + // middlewares. + if (splitPath[1] === '_oauth_apps') { + return splitPath.slice(2); + } +} + +export const routes = { + // :path/:provider/:app/callback + appCallback: (req) => { + const paths = getPaths(req); + + if (paths && paths[2] === 'callback') { + return { + provider: paths[0], + app: paths[1] + }; + } + }, + // :path/providers + providers: (req) => { + const paths = getPaths(req); + + return paths && paths[0] === 'providers'; + } +}; diff --git a/packages/rocketchat-grant/server/settings.js b/packages/rocketchat-grant/server/settings.js new file mode 100644 index 000000000000..e53b466fa87f --- /dev/null +++ b/packages/rocketchat-grant/server/settings.js @@ -0,0 +1,42 @@ +import { check } from 'meteor/check'; + +import { Storage } from './storage'; + +class Apps extends Storage { + add(name, body) { + check(name, String); + check(body, { + redirectUrl: String, + errorUrl: String + }); + + this._add(name, body); + } +} + +class Settings extends Storage { + constructor() { + super(); + + this.apps = new Apps; + } + add(settings) { + check(settings, { + enabled: Match.Optional(Boolean), + provider: String, + key: String, + secret: String + }); + + this._add(settings.provider, { + enabled: settings.enabled === true, + provider: settings.provider, + key: settings.key, + secret: settings.secret + }); + } +} + +const settings = new Settings; + +export default settings; diff --git a/packages/rocketchat-grant/server/storage.js b/packages/rocketchat-grant/server/storage.js new file mode 100644 index 000000000000..90d506681a83 --- /dev/null +++ b/packages/rocketchat-grant/server/storage.js @@ -0,0 +1,33 @@ +export class Storage { + constructor() { + this._data = {}; + } + + all() { + return this._data; + } + + forEach(fn) { + Object.keys(this.all()) + .forEach((name) => { + fn(this.get(name), name); + }); + } + + get(name) { + return this.all()[name.toLowerCase()]; + } + + has(name) { + return !!this._data[name]; + } + + _add(name, body) { + if (this.has(name)) { + console.error(`'${ name }' have been already defined`); + return; + } + + this._data[name] = body; + } +} diff --git a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json index 13032f7d6a0d..482cfcaf4242 100644 --- a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json @@ -71,8 +71,8 @@ "from": "cookie-signature@1.0.6" }, "core-js": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.4.1.tgz", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.0.tgz", "from": "core-js@>=2.4.0 <3.0.0" }, "cors": { @@ -218,16 +218,9 @@ "from": "hoek@>=2.0.0 <3.0.0" }, "http-errors": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.1.tgz", - "from": "http-errors@>=1.6.1 <1.7.0", - "dependencies": { - "depd": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.0.tgz", - "from": "depd@1.1.0" - } - } + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", + "from": "http-errors@>=1.6.1 <1.7.0" }, "iconv-lite": { "version": "0.4.15", diff --git a/packages/rocketchat-graphql/package.js b/packages/rocketchat-graphql/package.js index 24f1b58779af..1fbde6720c12 100644 --- a/packages/rocketchat-graphql/package.js +++ b/packages/rocketchat-graphql/package.js @@ -9,6 +9,7 @@ Package.onUse(function(api) { api.use([ 'underscore', 'ecmascript', + 'http', 'rocketchat:lib', 'rocketchat:api', 'rocketchat:accounts' diff --git a/packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.js b/packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.js new file mode 100644 index 000000000000..dd4a4253fd37 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.js @@ -0,0 +1,5 @@ +export const schema = ` + type OauthProvider { + name: String! + } +`; diff --git a/packages/rocketchat-graphql/server/schemas/accounts/index.js b/packages/rocketchat-graphql/server/schemas/accounts/index.js index cf41ed398f04..e82a7077059b 100644 --- a/packages/rocketchat-graphql/server/schemas/accounts/index.js +++ b/packages/rocketchat-graphql/server/schemas/accounts/index.js @@ -1,8 +1,21 @@ import { createJSAccountsGraphQL } from '@accounts/graphql-api'; import { AccountsServer } from 'meteor/rocketchat:accounts'; +import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; + +// queries +import * as oauthProviders from './oauthProviders'; +// types +import * as OauthProviderType from './OauthProvider-type'; const accountsGraphQL = createJSAccountsGraphQL(AccountsServer); -export const schema = accountsGraphQL.schema; +export const schema = mergeTypes([ + accountsGraphQL.schema, + oauthProviders.schema, + OauthProviderType.schema +]); -export const resolvers = accountsGraphQL.extendWithResolvers({}); +export const resolvers = mergeResolvers([ + accountsGraphQL.extendWithResolvers({}), + oauthProviders.resolver +]); diff --git a/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.js b/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.js new file mode 100644 index 000000000000..270f17a355b7 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.js @@ -0,0 +1,41 @@ +import { HTTP } from 'meteor/http'; +import { Meteor } from 'meteor/meteor'; + +function isJSON(obj) { + try { + JSON.parse(obj); + return true; + } catch (e) { + return false; + } +} + +export const schema = ` + type Query { + oauthProviders: [OauthProvider] + } +`; + +export const resolver = { + Query: { + oauthProviders: async() => { + // depends on rocketchat:grant package + try { + const url = Meteor.absoluteUrl('_oauth_apps/providers'); + console.log('url', url); + const result = HTTP.get(Meteor.absoluteUrl('_oauth_apps/providers')).content; + + if (isJSON(result)) { + const providers = JSON.parse(result).data; + + return providers.map((name) => ({ name })); + } else { + throw new Error('Could not parse the result'); + } + } catch (e) { + console.error('oauthProviders resolver', e); + throw new Error('rocketchat:grant not installed'); + } + } + } +}; diff --git a/server/configuration/grant.js b/server/configuration/grant.js new file mode 100644 index 000000000000..f12a59c300be --- /dev/null +++ b/server/configuration/grant.js @@ -0,0 +1,27 @@ +import { Settings } from 'meteor/rocketchat:grant'; + +Settings.add({ + enabled: true, + provider: 'github', + key: '96db2753350cfe8c8ae1', + secret: '546317a561df5e3d350fca9b5500f270b54f3301' +}); + +Settings.add({ + enabled: true, + provider: 'facebook', + key: '494859557516801', + secret: '5274d3495cebaf01f7e1b90fe1331fba' +}); + +Settings.add({ + enabled: true, + provider: 'google', + key: '979285364697-pob8soqche90ng1af0pj9if6ed69jalh.apps.googleusercontent.com', + secret: 'lFWtrtJngtlNBdrAoevwPjZh' +}); + +Settings.apps.add('pwa', { + redirectUrl: 'http://localhost:4200/login?service={provider}&access_token={accessToken}&refresh_token={refreshToken}', + errorUrl: 'http://localhost:4200/login?service={provider}&error={error}' +}); From e6e9b1be357ea044b80934f9170bc15e3fff2f4d Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 9 Aug 2017 18:51:43 +0200 Subject: [PATCH 15/42] Moar --- .../rocketchat-grant-facebook/server/index.js | 19 +++++-------------- .../rocketchat-grant-github/server/index.js | 15 ++++++--------- .../rocketchat-grant-google/server/index.js | 13 ++++--------- .../rocketchat-grant/server/authenticate.js | 13 +++++++++---- packages/rocketchat-grant/server/error.js | 5 +++++ packages/rocketchat-grant/server/index.js | 4 +++- packages/rocketchat-grant/server/redirect.js | 6 +++++- .../server/schemas/messages/Message-type.js | 2 ++ .../server/schemas/messages/messages.js | 7 ++++++- 9 files changed, 45 insertions(+), 39 deletions(-) create mode 100644 packages/rocketchat-grant/server/error.js diff --git a/packages/rocketchat-grant-facebook/server/index.js b/packages/rocketchat-grant-facebook/server/index.js index 882ef18ac129..7dc87f6494f9 100644 --- a/packages/rocketchat-grant-facebook/server/index.js +++ b/packages/rocketchat-grant-facebook/server/index.js @@ -1,4 +1,4 @@ -import { Providers } from 'meteor/rocketchat:grant'; +import { Providers, GrantError } from 'meteor/rocketchat:grant'; import { HTTP } from 'meteor/http'; const userAgent = 'Meteor'; @@ -15,11 +15,7 @@ function getIdentity(accessToken, fields) { } }).data; } catch (err) { - console.log('err', err); - throw Object.assign( - new Error(`Failed to fetch identity from Facebook. ${ err.message }`), - { response: err.response } - ); + throw new GrantError(`Failed to fetch identity from Facebook. ${ err.message }`); } } @@ -37,10 +33,7 @@ function getPicture(accessToken) { } }).data; } catch (err) { - throw Object.assign( - new Error(`Failed to fetch profile picture from Facebook. ${ err.message }`), - { response: err.response } - ); + throw new GrantError(`Failed to fetch profile picture from Facebook. ${ err.message }`); } } @@ -54,10 +47,8 @@ export function getUser(accessToken) { id: identity.id, email: identity.email, username, - profile: { - name: `${ identity.first_name } ${ identity.last_name }`, - avatar: avatar.data.url - } + name: `${ identity.first_name } ${ identity.last_name }`, + avatar: avatar.data.url }; } diff --git a/packages/rocketchat-grant-github/server/index.js b/packages/rocketchat-grant-github/server/index.js index 4359fe07754b..2d82479b7e09 100644 --- a/packages/rocketchat-grant-github/server/index.js +++ b/packages/rocketchat-grant-github/server/index.js @@ -1,4 +1,4 @@ -import { Providers } from 'meteor/rocketchat:grant'; +import { Providers, GrantError } from 'meteor/rocketchat:grant'; import { HTTP } from 'meteor/http'; const userAgent = 'Meteor'; @@ -11,10 +11,7 @@ function getIdentity(accessToken) { params: { access_token: accessToken } }).data; } catch (err) { - throw Object.assign( - new Error(`Failed to fetch identity from Github. ${ err.message }`), - { response: err.response } - ); + throw new GrantError(`Failed to fetch identity from Github. ${ err.message }`); } } @@ -35,15 +32,15 @@ export function getUser(accessToken) { const emails = getEmails(accessToken); const primaryEmail = (emails || []).find(email => email.primary === true); + console.log('identity', identity); + return { id: identity.id, email: identity.email || (primaryEmail && primaryEmail.email) || '', username: identity.login, emails, - profile: { - name: identity.name, - avatar: identity.avatar_url - } + name: identity.name, + avatar: identity.avatar_url }; } diff --git a/packages/rocketchat-grant-google/server/index.js b/packages/rocketchat-grant-google/server/index.js index 5cc545c18cda..f1cf2ae853a6 100644 --- a/packages/rocketchat-grant-google/server/index.js +++ b/packages/rocketchat-grant-google/server/index.js @@ -1,4 +1,4 @@ -import { Providers } from 'meteor/rocketchat:grant'; +import { Providers, GrantError } from 'meteor/rocketchat:grant'; import { HTTP } from 'meteor/http'; const userAgent = 'Meteor'; @@ -13,10 +13,7 @@ function getIdentity(accessToken) { } }).data; } catch (err) { - throw Object.assign( - new Error(`Failed to fetch identity from Google. ${ err.message }`), - { response: err.response } - ); + throw new GrantError(`Failed to fetch identity from Google. ${ err.message }`); } } @@ -32,10 +29,8 @@ export function getUser(accessToken) { id: identity.id, email: identity.email, username, - profile: { - name: identity.name, - avatar: identity.picture - } + name: identity.name, + avatar: identity.picture }; } diff --git a/packages/rocketchat-grant/server/authenticate.js b/packages/rocketchat-grant/server/authenticate.js index bf2512d1f1aa..33544467875b 100644 --- a/packages/rocketchat-grant/server/authenticate.js +++ b/packages/rocketchat-grant/server/authenticate.js @@ -1,6 +1,7 @@ import { AccountsServer } from 'meteor/rocketchat:accounts'; import { Accounts } from 'meteor/accounts-base'; +import { GrantError } from './error'; import Providers from './providers'; const findUserByOAuthId = (providerName, id) => { @@ -40,11 +41,13 @@ export async function authenticate(providerName, req) { const provider = Providers.get(providerName); if (!provider) { - throw new Error(`Provider '${ providerName }' not found`); + throw new GrantError(`Provider '${ providerName }' not found`); } const userData = provider.getUser(accessToken); + console.log('userData', userData); + let user = findUserByOAuthId(providerName, userData.id); if (user) { @@ -64,17 +67,19 @@ export async function authenticate(providerName, req) { tokens = loginResult.tokens; } else { const id = Accounts.createUser({ - email: userData.email + email: userData.email, + username: userData.username }); RocketChat.models.Users.setProfile(id, { - name: userData.profile.name, - avatar: userData.profile.avatar, + avatar: userData.avatar, oauth: { [providerName]: userData.id } }); + RocketChat.models.Users.setName(id, userData.name); + const loginResult = await AccountsServer.loginWithUser({ id }); tokens = loginResult.tokens; diff --git a/packages/rocketchat-grant/server/error.js b/packages/rocketchat-grant/server/error.js new file mode 100644 index 000000000000..16ab38913db8 --- /dev/null +++ b/packages/rocketchat-grant/server/error.js @@ -0,0 +1,5 @@ +export class GrantError extends Error { + constructor(...args) { + super(...args); + } +} diff --git a/packages/rocketchat-grant/server/index.js b/packages/rocketchat-grant/server/index.js index fc06ae57ba3a..5aec92218200 100644 --- a/packages/rocketchat-grant/server/index.js +++ b/packages/rocketchat-grant/server/index.js @@ -3,6 +3,7 @@ import session from 'express-session'; import Grant from 'grant-express'; import fiber from 'fibers'; +import { GrantError } from './error'; import { generateConfig } from './grant'; import { path, generateCallback, generateAppCallback } from './routes'; import { middleware as redirect } from './redirect'; @@ -51,5 +52,6 @@ export { generateCallback, generateAppCallback, Providers, - Settings + Settings, + GrantError }; diff --git a/packages/rocketchat-grant/server/redirect.js b/packages/rocketchat-grant/server/redirect.js index 25faad1e1ca9..2423758f48ca 100644 --- a/packages/rocketchat-grant/server/redirect.js +++ b/packages/rocketchat-grant/server/redirect.js @@ -1,6 +1,7 @@ import { authenticate } from './authenticate'; import Settings from './settings'; import { routes } from './routes'; +import { GrantError } from './error'; function parseUrl(url, config) { return url.replace(/\{[\ ]*(provider|accessToken|refreshToken|error)[\ ]*\}/g, (_, key) => config[key]); @@ -39,7 +40,10 @@ export async function middleware(req, res, next) { res.redirect(parseUrl(redirectUrl, config)); return; } catch (error) { - config.error = error.message; + config.error = error instanceof GrantError ? error.message : 'Something went wrong'; + + console.error(error); + res.redirect(parseUrl(errorUrl, config)); return; } diff --git a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js index 09204793acf7..b1234eb9a574 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js +++ b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js @@ -9,6 +9,7 @@ export const schema = ` channel: Channel creationTime: Float fromServer: Boolean + type: String userRef: [User] channelRef: [Channel] reactions: [Reaction] @@ -29,6 +30,7 @@ export const resolver = { return RocketChat.models.Rooms.findOne(root.rid); }, fromServer: (root) => typeof root.t !== 'undefined', // on a message sent by user `true` otherwise `false` + type: property('t'), channelRef: (root) => { if (!root.channels) { return; diff --git a/packages/rocketchat-graphql/server/schemas/messages/messages.js b/packages/rocketchat-graphql/server/schemas/messages/messages.js index ad8bb24cdfed..b47062932e96 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/messages.js +++ b/packages/rocketchat-graphql/server/schemas/messages/messages.js @@ -8,7 +8,8 @@ export const schema = ` channelName: String, cursor: String, count: Int, - searchRegex: String + searchRegex: String, + excludeServer: Boolean ): MessagesWithCursor } `; @@ -59,6 +60,10 @@ export const resolver = { messagesOptions.limit = args.count; } + if (args.excludeServer === true) { + messagesQuery.t = { $exists: false }; + } + const messages = RocketChat.models.Messages.find( Object.assign({}, messagesQuery, { rid: channel._id }), messagesOptions From 09157fe1d5a33ea3be7cd66310560847d379c746 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 9 Aug 2017 19:04:17 +0200 Subject: [PATCH 16/42] Remove console.logs and set email as verified --- packages/rocketchat-grant-github/server/index.js | 2 -- packages/rocketchat-grant/server/authenticate.js | 4 +--- .../server/schemas/accounts/oauthProviders.js | 2 -- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/rocketchat-grant-github/server/index.js b/packages/rocketchat-grant-github/server/index.js index 2d82479b7e09..1358986420c3 100644 --- a/packages/rocketchat-grant-github/server/index.js +++ b/packages/rocketchat-grant-github/server/index.js @@ -32,8 +32,6 @@ export function getUser(accessToken) { const emails = getEmails(accessToken); const primaryEmail = (emails || []).find(email => email.primary === true); - console.log('identity', identity); - return { id: identity.id, email: identity.email || (primaryEmail && primaryEmail.email) || '', diff --git a/packages/rocketchat-grant/server/authenticate.js b/packages/rocketchat-grant/server/authenticate.js index 33544467875b..305ff3ad37c6 100644 --- a/packages/rocketchat-grant/server/authenticate.js +++ b/packages/rocketchat-grant/server/authenticate.js @@ -46,8 +46,6 @@ export async function authenticate(providerName, req) { const userData = provider.getUser(accessToken); - console.log('userData', userData); - let user = findUserByOAuthId(providerName, userData.id); if (user) { @@ -77,8 +75,8 @@ export async function authenticate(providerName, req) { [providerName]: userData.id } }); - RocketChat.models.Users.setName(id, userData.name); + RocketChat.models.Users.setEmailVerified(id, userData.email); const loginResult = await AccountsServer.loginWithUser({ id }); diff --git a/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.js b/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.js index 270f17a355b7..9cefedb7a15e 100644 --- a/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.js +++ b/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.js @@ -21,8 +21,6 @@ export const resolver = { oauthProviders: async() => { // depends on rocketchat:grant package try { - const url = Meteor.absoluteUrl('_oauth_apps/providers'); - console.log('url', url); const result = HTTP.get(Meteor.absoluteUrl('_oauth_apps/providers')).content; if (isJSON(result)) { From 4d5e0b616dc2341bdd3806039c153c08e9fb6754 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 17 Aug 2017 16:09:56 +0200 Subject: [PATCH 17/42] Implemented saving avatars properly and fixed messages sorting (DESC `ts`) --- .../rocketchat-grant/server/authenticate.js | 23 +++++++++++++++++++ .../server/schemas/messages/Message-type.js | 4 +++- .../server/schemas/messages/messages.js | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-grant/server/authenticate.js b/packages/rocketchat-grant/server/authenticate.js index 305ff3ad37c6..ad68fb009681 100644 --- a/packages/rocketchat-grant/server/authenticate.js +++ b/packages/rocketchat-grant/server/authenticate.js @@ -1,9 +1,30 @@ import { AccountsServer } from 'meteor/rocketchat:accounts'; import { Accounts } from 'meteor/accounts-base'; +import { Meteor } from 'meteor/meteor'; import { GrantError } from './error'; import Providers from './providers'; +const setAvatarFromUrl = (userId, url) => { + return new Promise((resolve, reject) => { + Meteor.runAsUser(userId, () => { + Meteor.call('setAvatarFromService', url, '', 'url', (err) => { + if (err) { + if (err.details.timeToReset && err.details.timeToReset) { + reject((t('error-too-many-requests', { + seconds: parseInt(err.details.timeToReset / 1000) + }))); + } else { + reject(t('Avatar_url_invalid_or_error')); + } + } else { + resolve(); + } + }); + }); + }); +}; + const findUserByOAuthId = (providerName, id) => { return RocketChat.models.Users.findOne({ [`settings.profile.oauth.${ providerName }`]: id }); }; @@ -78,6 +99,8 @@ export async function authenticate(providerName, req) { RocketChat.models.Users.setName(id, userData.name); RocketChat.models.Users.setEmailVerified(id, userData.email); + await setAvatarFromUrl(id, userData.avatar); + const loginResult = await AccountsServer.loginWithUser({ id }); tokens = loginResult.tokens; diff --git a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js index b1234eb9a574..177a84bd213c 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js +++ b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js @@ -24,7 +24,9 @@ export const resolver = { content: property('msg'), creationTime: (root) => dateToFloat(root.ts), author: (root) => { - return RocketChat.models.Users.findOne(root.u._id); + const user = RocketChat.models.Users.findOne(root.u._id); + + return user || root.u; }, channel: (root) => { return RocketChat.models.Rooms.findOne(root.rid); diff --git a/packages/rocketchat-graphql/server/schemas/messages/messages.js b/packages/rocketchat-graphql/server/schemas/messages/messages.js index b47062932e96..8083d2fa6fdf 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/messages.js +++ b/packages/rocketchat-graphql/server/schemas/messages/messages.js @@ -19,7 +19,7 @@ export const resolver = { messages: authenticated((root, args) => { const messagesQuery = {}; const messagesOptions = { - sort: { ts: 1 } + sort: { ts: -1 } }; const channelQuery = {}; const isPagination = !!args.cursor || args.count > 0; From f90e302a15efa0fe6b5dbc6c1ceb91fb6f3e9193 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 29 Aug 2017 11:40:38 +0200 Subject: [PATCH 18/42] Use findOneByRoomIdAndUserId instead of custom one --- .../server/helpers/findChannelByIdAndUser.js | 8 -------- .../server/schemas/channels/Channel-type.js | 17 ++--------------- 2 files changed, 2 insertions(+), 23 deletions(-) delete mode 100644 packages/rocketchat-graphql/server/helpers/findChannelByIdAndUser.js diff --git a/packages/rocketchat-graphql/server/helpers/findChannelByIdAndUser.js b/packages/rocketchat-graphql/server/helpers/findChannelByIdAndUser.js deleted file mode 100644 index b36f972203e6..000000000000 --- a/packages/rocketchat-graphql/server/helpers/findChannelByIdAndUser.js +++ /dev/null @@ -1,8 +0,0 @@ -export function findChannelByIdAndUser({ params, options = {} }) { - const sub = RocketChat.models.Subscriptions.findOne({ - rid: params.roomId, - 'u._id': params.userId - }, options); - - return sub; -} diff --git a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js index b980acad0f7b..cfcbebe2a327 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js +++ b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js @@ -1,5 +1,4 @@ import { property } from '../../helpers/property'; -import { findChannelByIdAndUser } from '../../helpers/findChannelByIdAndUser'; export const schema = ` type Channel { @@ -49,24 +48,12 @@ export const resolver = { direct: (root) => root.t === 'd', privateChannel: (root) => root.t === 'p', favourite: (root, args, { user }) => { - const room = findChannelByIdAndUser({ - params: { - roomId: root._id, - userId: user._id - }, - options: { fields: { f: 1 }} - }); + const room = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(root._id, user._id); return room && room.f === true; }, unseenMessages: (root, args, { user }) => { - const room = findChannelByIdAndUser({ - params: { - roomId: root._id, - userId: user._id - }, - options: { fields: { unread: 1 }} - }); + const room = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(root._id, user._id); return (room || {}).unread; } From c522dd9a5262fe17fee22f3656df97becf4eb0fa Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 29 Aug 2017 13:00:43 +0200 Subject: [PATCH 19/42] Update deps in rocketchat:graphql --- packages/rocketchat-graphql/package.js | 13 ++++++------- packages/rocketchat-graphql/server/api.js | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/rocketchat-graphql/package.js b/packages/rocketchat-graphql/package.js index 1fbde6720c12..b4ceb319ed9b 100644 --- a/packages/rocketchat-graphql/package.js +++ b/packages/rocketchat-graphql/package.js @@ -20,14 +20,13 @@ Package.onUse(function(api) { Npm.depends({ '@accounts/graphql-api': '0.1.1', - 'apollo-client': '1.6.0', - 'cors': '2.8.3', + 'apollo-server-express': '1.1.2', + 'cors': '2.8.4', 'body-parser': '1.17.2', - 'express': '4.15.3', + 'express': '4.15.4', 'graphql': '0.10.3', - 'graphql-server-express': '0.9.0', 'graphql-subscriptions': '0.4.4', - 'graphql-tools': '1.1.0', - 'merge-graphql-schemas': '1.1.0', - 'subscriptions-transport-ws': '0.8.1' + 'graphql-tools': '1.2.2', + 'merge-graphql-schemas': '1.1.2', + 'subscriptions-transport-ws': '0.8.2' }); diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index 7a82b6acec00..a8262a0d33f4 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -1,4 +1,4 @@ -import { graphqlExpress, graphiqlExpress } from 'graphql-server-express'; +import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'; import { JSAccountsContext as jsAccountsContext } from '@accounts/graphql-api'; import { SubscriptionServer } from 'subscriptions-transport-ws'; import { execute, subscribe } from 'graphql'; From 7a6bce9317cd0d9b22fce4c192fe8d0d4b5a80be Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 29 Aug 2017 13:03:54 +0200 Subject: [PATCH 20/42] Add comments on the schema about meaning of the types --- .../rocketchat-graphql/server/schemas/messages/Message-type.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js index 177a84bd213c..b6567e26f40c 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js +++ b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js @@ -8,9 +8,12 @@ export const schema = ` content: String channel: Channel creationTime: Float + # Message sent by server e.g. User joined channel fromServer: Boolean type: String + # List of mentioned users userRef: [User] + # list of mentioned channels channelRef: [Channel] reactions: [Reaction] # TODO From eac0aac4793e37b2e49459038eaf7127bf573ecb Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 29 Aug 2017 13:06:44 +0200 Subject: [PATCH 21/42] Remove unnecessary return statement --- packages/rocketchat-graphql/server/schemas/users/User-type.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/rocketchat-graphql/server/schemas/users/User-type.js b/packages/rocketchat-graphql/server/schemas/users/User-type.js index 34978665bcdb..3891f47e1d65 100644 --- a/packages/rocketchat-graphql/server/schemas/users/User-type.js +++ b/packages/rocketchat-graphql/server/schemas/users/User-type.js @@ -25,7 +25,6 @@ export const resolver = { if (avatar) { return avatar.url; } - return; }, channels: ({ _id }) => { return RocketChat.models.Rooms.findBySubscriptionUserId(_id).fetch(); From 10e4b273fe0982a06ffdf00d2c1db90590663d92 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 29 Aug 2017 13:07:36 +0200 Subject: [PATCH 22/42] Remove unused todos from Message type --- .../server/schemas/messages/Message-type.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js index b6567e26f40c..264ef427390b 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js +++ b/packages/rocketchat-graphql/server/schemas/messages/Message-type.js @@ -16,8 +16,6 @@ export const schema = ` # list of mentioned channels channelRef: [Channel] reactions: [Reaction] - # TODO - tags: [String] } `; @@ -83,8 +81,6 @@ export const resolver = { }); return reactions; - }, - // TODO - tags: () => {} + } } }; From 0fff6a00712d0574e4ef332e794dde5b4f0892f3 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Thu, 31 Aug 2017 16:59:33 +0200 Subject: [PATCH 23/42] READMEs, separate schema from resolvers, fix sorting and cursor messages resolver, graphql.config.json --- .meteor/versions | 1 + graphql.config.json | 9 + .../.npm/package/npm-shrinkwrap.json | 45 ++- packages/rocketchat-accounts/package.js | 3 +- packages/rocketchat-accounts/server/fix.js | 3 - packages/rocketchat-accounts/server/index.js | 2 +- packages/rocketchat-api/server/v1/channels.js | 93 +++-- packages/rocketchat-grant-facebook/README.md | 3 + packages/rocketchat-grant-github/README.md | 3 + packages/rocketchat-grant-google/README.md | 3 + packages/rocketchat-grant/README.md | 109 +++++- packages/rocketchat-grant/server/providers.js | 1 - .../.npm/package/npm-shrinkwrap.json | 337 +++++++++--------- packages/rocketchat-graphql/README.md | 3 + packages/rocketchat-graphql/package.js | 7 +- packages/rocketchat-graphql/server/api.js | 2 +- .../server/helpers/authenticated.js | 2 +- .../server/mocks/accounts/graphql-api.js | 10 - .../server/mocks/accounts/server.js | 13 - .../resolvers/accounts/OauthProvider-type.js | 5 + .../{schemas => resolvers}/accounts/index.js | 4 +- .../accounts/oauthProviders.js | 16 +- .../channels/Channel-type.js | 27 +- .../resolvers/channels/ChannelFilter-input.js | 5 + .../channels/ChannelNameAndDirect-input.js | 5 + .../resolvers/channels/ChannelSort-enum.js | 5 + .../server/resolvers/channels/Privacy-enum.js | 5 + .../channels/channelByName.js | 14 +- .../channels/channels.js | 22 +- .../channels/channelsByUser.js | 16 +- .../resolvers/channels/createChannel.js | 38 ++ .../channels/directChannel.js | 15 +- .../channels/hideChannel.js | 14 +- .../{schemas => resolvers}/channels/index.js | 2 +- .../channels/leaveChannel.js | 14 +- .../channels/settings.js | 0 .../messages/Message-type.js | 26 +- .../messages/MessageIdentifier-input.js | 5 + .../messages/MessagesWithCursor-type.js | 5 + .../resolvers/messages/Reaction-type.js | 5 + .../messages/addReactionToMessage.js | 14 +- .../messages/chatMessageAdded.js | 14 +- .../messages/deleteMessage.js | 14 +- .../messages/editMessage.js | 14 +- .../{schemas => resolvers}/messages/index.js | 2 +- .../messages/messages.js | 43 ++- .../messages/sendMessage.js | 14 +- .../{schemas => resolvers}/users/User-type.js | 23 +- .../server/resolvers/users/UserStatus-enum.js | 5 + .../{schemas => resolvers}/users/index.js | 2 +- .../{schemas => resolvers}/users/setStatus.js | 14 +- packages/rocketchat-graphql/server/schema.js | 15 +- .../schemas/accounts/LoginResult-type.graphql | 4 + .../schemas/accounts/LoginResult-type.js | 6 - .../accounts/OauthProvider-type.graphql | 3 + .../schemas/accounts/OauthProvider-type.js | 5 - .../schemas/accounts/oauthProviders.graphql | 3 + .../schemas/channels/Channel-type.graphql | 16 + .../channels/ChannelFilter-input.graphql | 6 + .../schemas/channels/ChannelFilter-input.js | 8 - .../ChannelNameAndDirect-input.graphql | 4 + .../channels/ChannelNameAndDirect-input.js | 6 - .../schemas/channels/ChannelSort-enum.graphql | 4 + .../schemas/channels/ChannelSort-enum.js | 6 - .../schemas/channels/Privacy-enum.graphql | 5 + .../server/schemas/channels/Privacy-enum.js | 7 - .../schemas/channels/channelByName.graphql | 3 + .../server/schemas/channels/channels.graphql | 7 + .../schemas/channels/channelsByUser.graphql | 3 + .../schemas/channels/createChannel.graphql | 8 + .../server/schemas/channels/createChannel.js | 45 --- .../schemas/channels/directChannel.graphql | 3 + .../schemas/channels/hideChannel.graphql | 3 + .../schemas/channels/leaveChannel.graphql | 3 + .../schemas/messages/Message-type.graphql | 15 + .../messages/MessageIdentifier-input.graphql | 4 + .../messages/MessageIdentifier-input.js | 6 - .../messages/MessagesWithCursor-type.graphql | 5 + .../messages/MessagesWithCursor-type.js | 7 - .../schemas/messages/Reaction-type.graphql | 4 + .../server/schemas/messages/Reaction-type.js | 6 - .../messages/addReactionToMessage.graphql | 3 + .../schemas/messages/chatMessageAdded.graphql | 3 + .../schemas/messages/deleteMessage.graphql | 3 + .../schemas/messages/editMessage.graphql | 3 + .../server/schemas/messages/messages.graphql | 11 + .../schemas/messages/sendMessage.graphql | 3 + .../server/schemas/users/User-type.graphql | 8 + .../schemas/users/UserStatus-enum.graphql | 7 + .../server/schemas/users/UserStatus-enum.js | 9 - .../server/schemas/users/setStatus.graphql | 3 + 91 files changed, 778 insertions(+), 551 deletions(-) create mode 100644 graphql.config.json delete mode 100644 packages/rocketchat-accounts/server/fix.js create mode 100644 packages/rocketchat-grant-facebook/README.md create mode 100644 packages/rocketchat-grant-github/README.md create mode 100644 packages/rocketchat-grant-google/README.md create mode 100644 packages/rocketchat-graphql/README.md delete mode 100644 packages/rocketchat-graphql/server/mocks/accounts/server.js create mode 100644 packages/rocketchat-graphql/server/resolvers/accounts/OauthProvider-type.js rename packages/rocketchat-graphql/server/{schemas => resolvers}/accounts/index.js (76%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/accounts/oauthProviders.js (80%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/channels/Channel-type.js (75%) create mode 100644 packages/rocketchat-graphql/server/resolvers/channels/ChannelFilter-input.js create mode 100644 packages/rocketchat-graphql/server/resolvers/channels/ChannelNameAndDirect-input.js create mode 100644 packages/rocketchat-graphql/server/resolvers/channels/ChannelSort-enum.js create mode 100644 packages/rocketchat-graphql/server/resolvers/channels/Privacy-enum.js rename packages/rocketchat-graphql/server/{schemas => resolvers}/channels/channelByName.js (73%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/channels/channels.js (80%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/channels/channelsByUser.js (78%) create mode 100644 packages/rocketchat-graphql/server/resolvers/channels/createChannel.js rename packages/rocketchat-graphql/server/{schemas => resolvers}/channels/directChannel.js (84%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/channels/hideChannel.js (87%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/channels/index.js (93%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/channels/leaveChannel.js (81%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/channels/settings.js (100%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/messages/Message-type.js (78%) create mode 100644 packages/rocketchat-graphql/server/resolvers/messages/MessageIdentifier-input.js create mode 100644 packages/rocketchat-graphql/server/resolvers/messages/MessagesWithCursor-type.js create mode 100644 packages/rocketchat-graphql/server/resolvers/messages/Reaction-type.js rename packages/rocketchat-graphql/server/{schemas => resolvers}/messages/addReactionToMessage.js (74%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/messages/chatMessageAdded.js (83%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/messages/deleteMessage.js (83%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/messages/editMessage.js (85%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/messages/index.js (93%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/messages/messages.js (66%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/messages/sendMessage.js (75%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/users/User-type.js (65%) create mode 100644 packages/rocketchat-graphql/server/resolvers/users/UserStatus-enum.js rename packages/rocketchat-graphql/server/{schemas => resolvers}/users/index.js (82%) rename packages/rocketchat-graphql/server/{schemas => resolvers}/users/setStatus.js (73%) create mode 100644 packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.graphql delete mode 100644 packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.js create mode 100644 packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.graphql delete mode 100644 packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.js create mode 100644 packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/channels/Channel-type.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.graphql delete mode 100644 packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.graphql delete mode 100644 packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.graphql delete mode 100644 packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.graphql delete mode 100644 packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/channelByName.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/channels/channels.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/channels/channelsByUser.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/channels/createChannel.graphql delete mode 100644 packages/rocketchat-graphql/server/schemas/channels/createChannel.js create mode 100644 packages/rocketchat-graphql/server/schemas/channels/directChannel.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/channels/hideChannel.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/channels/leaveChannel.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/messages/Message-type.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.graphql delete mode 100644 packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.graphql delete mode 100644 packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/Reaction-type.graphql delete mode 100644 packages/rocketchat-graphql/server/schemas/messages/Reaction-type.js create mode 100644 packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/messages/deleteMessage.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/messages/editMessage.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/messages/messages.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/users/User-type.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.graphql delete mode 100644 packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.js create mode 100644 packages/rocketchat-graphql/server/schemas/users/setStatus.graphql diff --git a/.meteor/versions b/.meteor/versions index e178545da53a..c608ae9d789f 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -246,6 +246,7 @@ spacebars-compiler@1.1.3 srp@1.0.10 standard-minifier-js@2.1.1 steffo:meteor-accounts-saml@0.0.1 +swydo:graphql@0.0.3 tap:i18n@1.8.2 templating@1.3.2 templating-compiler@1.3.2 diff --git a/graphql.config.json b/graphql.config.json new file mode 100644 index 000000000000..2c316a3dbb9f --- /dev/null +++ b/graphql.config.json @@ -0,0 +1,9 @@ +{ + "schema": { + "request": { + "url" : "http://localhost:3000/graphql", + "method" : "POST", + "postIntrospectionQuery" : true + } + } +} diff --git a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json index 548e1696bac6..720452518c3b 100644 --- a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json @@ -6,14 +6,21 @@ "from": "addressparser@>=0.3.2 <0.4.0" }, "babel-polyfill": { - "version": "6.23.0", - "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.23.0.tgz", + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", "from": "babel-polyfill@>=6.23.0 <7.0.0" }, "babel-runtime": { - "version": "6.25.0", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.25.0.tgz", - "from": "babel-runtime@>=6.22.0 <7.0.0" + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", + "from": "babel-runtime@>=6.26.0 <7.0.0", + "dependencies": { + "regenerator-runtime": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz", + "from": "regenerator-runtime@>=0.11.0 <0.12.0" + } + } }, "base64url": { "version": "2.0.0", @@ -48,7 +55,7 @@ "core-js": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.0.tgz", - "from": "core-js@>=2.4.0 <3.0.0" + "from": "core-js@>=2.5.0 <3.0.0" }, "core-util-is": { "version": "1.0.2", @@ -66,8 +73,8 @@ "from": "ecdsa-sig-formatter@1.0.9" }, "emailjs": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/emailjs/-/emailjs-1.0.11.tgz", + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/emailjs/-/emailjs-1.0.12.tgz", "from": "emailjs@>=1.0.8 <2.0.0" }, "encoding": { @@ -111,8 +118,8 @@ "from": "joi@>=6.10.1 <7.0.0" }, "jsonwebtoken": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.2.tgz", + "version": "7.4.3", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.3.tgz", "from": "jsonwebtoken@>=7.2.1 <8.0.0" }, "jwa": { @@ -153,19 +160,19 @@ } }, "moment": { - "version": "2.11.2", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.11.2.tgz", - "from": "moment@2.11.2" + "version": "2.15.2", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.15.2.tgz", + "from": "moment@2.15.2" }, "mongodb": { - "version": "2.2.30", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.30.tgz", + "version": "2.2.31", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.31.tgz", "from": "mongodb@>=2.2.22 <3.0.0" }, "mongodb-core": { - "version": "2.1.14", - "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.14.tgz", - "from": "mongodb-core@2.1.14" + "version": "2.1.15", + "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.15.tgz", + "from": "mongodb-core@2.1.15" }, "ms": { "version": "2.0.0", @@ -185,7 +192,7 @@ "regenerator-runtime": { "version": "0.10.5", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", - "from": "regenerator-runtime@>=0.10.0 <0.11.0" + "from": "regenerator-runtime@>=0.10.5 <0.11.0" }, "require_optional": { "version": "1.0.1", diff --git a/packages/rocketchat-accounts/package.js b/packages/rocketchat-accounts/package.js index fd29a0c2ebae..777c614620ba 100644 --- a/packages/rocketchat-accounts/package.js +++ b/packages/rocketchat-accounts/package.js @@ -18,6 +18,5 @@ Package.onUse(function(api) { Npm.depends({ '@accounts/server': '0.0.18', - '@accounts/mongo': '0.0.12-0', - '@accounts/meteor-adapter': '0.1.1' + '@accounts/mongo': '0.0.12' }); diff --git a/packages/rocketchat-accounts/server/fix.js b/packages/rocketchat-accounts/server/fix.js deleted file mode 100644 index f1900a19c465..000000000000 --- a/packages/rocketchat-accounts/server/fix.js +++ /dev/null @@ -1,3 +0,0 @@ -import regeneratorRuntime from 'babel-runtime/regenerator'; - -global.regeneratorRuntime = regeneratorRuntime; diff --git a/packages/rocketchat-accounts/server/index.js b/packages/rocketchat-accounts/server/index.js index 87ec121feca8..88ebb9b52977 100644 --- a/packages/rocketchat-accounts/server/index.js +++ b/packages/rocketchat-accounts/server/index.js @@ -1,4 +1,4 @@ -import './fix'; +// import './fix'; import './config'; import AccountsServer from '@accounts/server'; diff --git a/packages/rocketchat-api/server/v1/channels.js b/packages/rocketchat-api/server/v1/channels.js index 15a6c3d0eaf4..86abc6ab38e6 100644 --- a/packages/rocketchat-api/server/v1/channels.js +++ b/packages/rocketchat-api/server/v1/channels.js @@ -126,37 +126,82 @@ RocketChat.API.v1.addRoute('channels.close', { authRequired: true }, { } }); -RocketChat.API.v1.addRoute('channels.create', { authRequired: true }, { - post() { - if (!RocketChat.authz.hasPermission(this.userId, 'create-c')) { - return RocketChat.API.v1.unauthorized(); - } +// Channel -> create - if (!this.bodyParams.name) { - return RocketChat.API.v1.failure('Body param "name" is required'); - } +function createChannelValidator(params) { + if (!RocketChat.authz.hasPermission(params.user.value, 'create-c')) { + throw new Error('unauthorized'); + } - if (this.bodyParams.members && !_.isArray(this.bodyParams.members)) { - return RocketChat.API.v1.failure('Body param "members" must be an array if provided'); - } + if (!params.name.value) { + throw new Error(`Param "${ params.name.key }" is required`); + } - if (this.bodyParams.customFields && !(typeof this.bodyParams.customFields === 'object')) { - return RocketChat.API.v1.failure('Body param "customFields" must be an object if provided'); - } + if (params.members.value && !_.isArray(params.members.value)) { + throw new Error(`Param "${ params.members.key }" must be an array if provided`); + } + + if (params.customFields.value && !(typeof params.customFields.value === 'object')) { + throw new Error(`Param "${ params.customFields.key }" must be an object if provided`); + } +} + +function createChannel(userId, params) { + let readOnly = false; + if (typeof params.readOnly !== 'undefined') { + readOnly = params.readOnly; + } + + let id; + Meteor.runAsUser(userId, () => { + id = Meteor.call('createChannel', params.name, params.members ? params.members : [], readOnly, params.customFields); + }); + + return { + channel: RocketChat.models.Rooms.findOneById(id.rid, { fields: RocketChat.API.v1.defaultFieldsToExclude }) + }; +} - let readOnly = false; - if (typeof this.bodyParams.readOnly !== 'undefined') { - readOnly = this.bodyParams.readOnly; +RocketChat.API.channels = {}; +RocketChat.API.channels.create = { + validate: createChannelValidator, + execute: createChannel +}; + +RocketChat.API.v1.addRoute('channels.create', { authRequired: true }, { + post() { + const userId = this.userId; + const bodyParams = this.bodyParams; + + let error; + + try { + RocketChat.API.create.validate({ + user: { + value: userId + }, + name: { + value: bodyParams.name, + key: 'name' + }, + members: { + value: bodyParams.members, + key: 'members' + } + }); + } catch (e) { + if (e.message === 'unauthorized') { + error = RocketChat.API.v1.unauthorized(); + } else { + error = RocketChat.API.v1.failure(e.message); + } } - let id; - Meteor.runAsUser(this.userId, () => { - id = Meteor.call('createChannel', this.bodyParams.name, this.bodyParams.members ? this.bodyParams.members : [], readOnly, this.bodyParams.customFields); - }); + if (error) { + return error; + } - return RocketChat.API.v1.success({ - channel: RocketChat.models.Rooms.findOneById(id.rid, { fields: RocketChat.API.v1.defaultFieldsToExclude }) - }); + return RocketChat.API.v1.success(RocketChat.API.channels.create.execute(userId, bodyParams)); } }); diff --git a/packages/rocketchat-grant-facebook/README.md b/packages/rocketchat-grant-facebook/README.md new file mode 100644 index 000000000000..9d2da06860b2 --- /dev/null +++ b/packages/rocketchat-grant-facebook/README.md @@ -0,0 +1,3 @@ +# rocketchat:grant-facebook + +An implementation of the Facebook OAuth flow. diff --git a/packages/rocketchat-grant-github/README.md b/packages/rocketchat-grant-github/README.md new file mode 100644 index 000000000000..e5fea3c781c7 --- /dev/null +++ b/packages/rocketchat-grant-github/README.md @@ -0,0 +1,3 @@ +# rocketchat:grant-github + +An implementation of the GitHub OAuth flow. diff --git a/packages/rocketchat-grant-google/README.md b/packages/rocketchat-grant-google/README.md new file mode 100644 index 000000000000..cdd59d97b562 --- /dev/null +++ b/packages/rocketchat-grant-google/README.md @@ -0,0 +1,3 @@ +# rocketchat:grant-google + +An implementation of the Google OAuth flow. diff --git a/packages/rocketchat-grant/README.md b/packages/rocketchat-grant/README.md index c526711cf6c9..716b57bfcf80 100644 --- a/packages/rocketchat-grant/README.md +++ b/packages/rocketchat-grant/README.md @@ -1,8 +1,101 @@ -1. Settings should be the same as in OAuth section -1. Should be extendable (rocketchat:grant, rocketchat:grant-github etc) -1. Each package with provider should transform it's scope to user data so we can register a new user -1. rocketchat:grant-sub - to define sub configurations to allow for using external apps -1. rocketchat:grant should contain a middleware and startup fn with setup, that is already in rocketchat:oauth-external -1. in callback it would create and / or log in a user -1. without any specified sub configuration, it would redirect to localhost:3000 by default -1. with a specified sub configuration it would redirect to a path and add access_token to the URL +# rocketchat:grant + +The main idea behind creating this package was to allow external apps (i.e. PWA) to use OAuth smoothely with currently available accounts system. + +## Usage + +1. Define providers using `Settings.add()` +1. Add apps with `Settings.apps.add()` +1. Put the path that stars OAuth flow in your app +1. You app should be able to authenticate user with received tokens + +## Paths + +There are few paths you need to be familiar with. + +### Start OAuth flow + +> \/_oauth_apps/connect/\/\ + +### Authorization callback URL + +> \/_oauth_apps/connect/\/callback + +### List of available providers + +> \/_oauth_apps/providers + +## API + +### Providers + +#### Providers.register(name, options, getUser) + +Allows to register an OAuth Provider. + +- name - string that represents the name of an OAuth provider +- options - contains fields like _scope_ +- getUser - a function that returns fields: _id, email, username, name and avatar_ + +### Settings + +#### Settings.add(options) + +Defines a provider that is able for being used in OAuth. + +**options**: + +- enabled - __boolean__ - tells to `rocketchat:grant` if provider could be used +- provider - __string__ - id of a provider +- key - __string__ - client ID provided for your OAuth access +- secret - __string__ - secret key + +Example: + +```js + Settings.add({ + enabled: true, + provider: 'google', + key: 'CLIENT_ID', + secret: 'SECRET' + }); +``` + +#### Settings.apps.add(name, options) + +Defines an app that is able for using OAuth. + +**options**: + +- redirectUrl - __string__ - where to redirect if auth was succesful +- errorUrl - __string__ - place to redirect on failure + +Example: + +```js + + const redirectUrl = 'http://localhost:4200/login?service={provider}&access_token={accessToken}&refresh_token={refreshToken}'; + + const errorUrl = 'http://localhost:4200/login?service={provider}&error={error}' + + + Settings.apps.add('PWA', { + redirectUrl, + errorUrl + }); +``` + +About URLs: + +We use a parser to produce a URL. +There are few available variables for each type of redirect. + +- redirectUrl - provider, accessToken, refreshToken +- errorUrl - provider, error + +Example: + +``` +http://localhost:4200/login?provider={provider} +// outputs: http://localhost:4200/login?provider=google +``` diff --git a/packages/rocketchat-grant/server/providers.js b/packages/rocketchat-grant/server/providers.js index 4b2aad10cee5..debad8d091e8 100644 --- a/packages/rocketchat-grant/server/providers.js +++ b/packages/rocketchat-grant/server/providers.js @@ -31,7 +31,6 @@ export function middleware(req, res, next) { providers.forEach((_, name) => list.push(name)); - // TODO: send a list of providers res.end(JSON.stringify({ data: list })); diff --git a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json index 482cfcaf4242..6a2374ea66c7 100644 --- a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json @@ -1,501 +1,512 @@ { "dependencies": { "accepts": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.3.tgz", - "from": "accepts@>=1.3.3 <1.4.0" + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.4.tgz", + "from": "accepts@https://registry.npmjs.org/accepts/-/accepts-1.3.4.tgz" + }, + "apollo-server-core": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/apollo-server-core/-/apollo-server-core-1.1.0.tgz", + "from": "apollo-server-core@https://registry.npmjs.org/apollo-server-core/-/apollo-server-core-1.1.0.tgz" }, - "apollo-client": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/apollo-client/-/apollo-client-1.6.0.tgz", - "from": "apollo-client@1.6.0" + "apollo-server-express": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/apollo-server-express/-/apollo-server-express-1.1.2.tgz", + "from": "apollo-server-express@https://registry.npmjs.org/apollo-server-express/-/apollo-server-express-1.1.2.tgz" + }, + "apollo-server-module-graphiql": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/apollo-server-module-graphiql/-/apollo-server-module-graphiql-1.1.2.tgz", + "from": "apollo-server-module-graphiql@https://registry.npmjs.org/apollo-server-module-graphiql/-/apollo-server-module-graphiql-1.1.2.tgz" + }, + "apollo-tracing": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/apollo-tracing/-/apollo-tracing-0.0.7.tgz", + "from": "apollo-tracing@https://registry.npmjs.org/apollo-tracing/-/apollo-tracing-0.0.7.tgz" }, "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "from": "array-flatten@1.1.1" + "from": "array-flatten@https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz" + }, + "babel-polyfill": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", + "from": "babel-polyfill@https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", + "dependencies": { + "regenerator-runtime": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", + "from": "regenerator-runtime@https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz" + } + } }, "babel-runtime": { - "version": "6.25.0", - "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.25.0.tgz", - "from": "babel-runtime@>=6.23.0 <7.0.0" + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", + "from": "babel-runtime@https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz" }, "backo2": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", - "from": "backo2@>=1.0.2 <2.0.0" + "from": "backo2@https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz" }, "base64url": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz", - "from": "base64url@>=2.0.0 <3.0.0" + "from": "base64url@https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz" }, "bcryptjs": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz", - "from": "bcryptjs@>=2.4.0 <3.0.0" + "from": "bcryptjs@https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz" }, "body-parser": { "version": "1.17.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.17.2.tgz", - "from": "body-parser@1.17.2" + "from": "body-parser@https://registry.npmjs.org/body-parser/-/body-parser-1.17.2.tgz" }, "buffer-equal-constant-time": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", - "from": "buffer-equal-constant-time@1.0.1" + "from": "buffer-equal-constant-time@https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz" }, "bytes": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz", - "from": "bytes@2.4.0" + "from": "bytes@https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz" }, "content-disposition": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", - "from": "content-disposition@0.5.2" + "from": "content-disposition@https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz" }, "content-type": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.2.tgz", - "from": "content-type@>=1.0.2 <1.1.0" + "from": "content-type@https://registry.npmjs.org/content-type/-/content-type-1.0.2.tgz" }, "cookie": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", - "from": "cookie@0.3.1" + "from": "cookie@https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz" }, "cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", - "from": "cookie-signature@1.0.6" + "from": "cookie-signature@https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz" }, "core-js": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.0.tgz", - "from": "core-js@>=2.4.0 <3.0.0" + "from": "core-js@https://registry.npmjs.org/core-js/-/core-js-2.5.0.tgz" }, "cors": { - "version": "2.8.3", - "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.3.tgz", - "from": "cors@2.8.3" + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.4.tgz", + "from": "cors@https://registry.npmjs.org/cors/-/cors-2.8.4.tgz" }, "crypto": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/crypto/-/crypto-0.0.3.tgz", - "from": "crypto@>=0.0.3 <0.0.4" + "from": "crypto@https://registry.npmjs.org/crypto/-/crypto-0.0.3.tgz" }, "debug": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.7.tgz", - "from": "debug@2.6.7" + "from": "debug@https://registry.npmjs.org/debug/-/debug-2.6.7.tgz" }, "deepmerge": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-1.5.0.tgz", - "from": "deepmerge@>=1.3.2 <2.0.0" + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-1.5.1.tgz", + "from": "deepmerge@https://registry.npmjs.org/deepmerge/-/deepmerge-1.5.1.tgz" }, "depd": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", - "from": "depd@>=1.1.0 <1.2.0" + "from": "depd@https://registry.npmjs.org/depd/-/depd-1.1.1.tgz" }, "deprecated-decorator": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz", - "from": "deprecated-decorator@>=0.1.6 <0.2.0" + "from": "deprecated-decorator@https://registry.npmjs.org/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz" }, "destroy": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "from": "destroy@>=1.0.4 <1.1.0" + "from": "destroy@https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz" }, "ecdsa-sig-formatter": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz", - "from": "ecdsa-sig-formatter@1.0.9" + "from": "ecdsa-sig-formatter@https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz" }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "from": "ee-first@1.1.1" + "from": "ee-first@https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz" }, "encodeurl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz", - "from": "encodeurl@>=1.0.1 <1.1.0" + "from": "encodeurl@https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz" }, "es6-promise": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.1.1.tgz", - "from": "es6-promise@>=4.0.5 <5.0.0" + "from": "es6-promise@https://registry.npmjs.org/es6-promise/-/es6-promise-4.1.1.tgz" }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "from": "escape-html@>=1.0.3 <1.1.0" + "from": "escape-html@https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz" }, "etag": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.0.tgz", - "from": "etag@>=1.8.0 <1.9.0" + "from": "etag@https://registry.npmjs.org/etag/-/etag-1.8.0.tgz" }, "eventemitter3": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz", - "from": "eventemitter3@>=2.0.3 <3.0.0" + "from": "eventemitter3@https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz" }, "express": { - "version": "4.15.3", - "resolved": "https://registry.npmjs.org/express/-/express-4.15.3.tgz", - "from": "express@4.15.3" + "version": "4.15.4", + "resolved": "https://registry.npmjs.org/express/-/express-4.15.4.tgz", + "from": "express@https://registry.npmjs.org/express/-/express-4.15.4.tgz", + "dependencies": { + "debug": { + "version": "2.6.8", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", + "from": "debug@https://registry.npmjs.org/debug/-/debug-2.6.8.tgz" + }, + "qs": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.0.tgz", + "from": "qs@https://registry.npmjs.org/qs/-/qs-6.5.0.tgz" + } + } }, "finalhandler": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.4.tgz", - "from": "finalhandler@>=1.0.3 <1.1.0", + "from": "finalhandler@https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.4.tgz", "dependencies": { "debug": { "version": "2.6.8", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "from": "debug@2.6.8" + "from": "debug@https://registry.npmjs.org/debug/-/debug-2.6.8.tgz" } } }, "forwarded": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.0.tgz", - "from": "forwarded@>=0.1.0 <0.2.0" + "from": "forwarded@https://registry.npmjs.org/forwarded/-/forwarded-0.1.0.tgz" }, "fresh": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.0.tgz", - "from": "fresh@0.5.0" + "from": "fresh@https://registry.npmjs.org/fresh/-/fresh-0.5.0.tgz" }, "graphql": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/graphql/-/graphql-0.10.3.tgz", - "from": "graphql@0.10.3" - }, - "graphql-anywhere": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/graphql-anywhere/-/graphql-anywhere-3.1.0.tgz", - "from": "graphql-anywhere@>=3.0.1 <4.0.0" - }, - "graphql-server-core": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/graphql-server-core/-/graphql-server-core-0.9.0.tgz", - "from": "graphql-server-core@>=0.9.0 <0.10.0" - }, - "graphql-server-express": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/graphql-server-express/-/graphql-server-express-0.9.0.tgz", - "from": "graphql-server-express@0.9.0" - }, - "graphql-server-module-graphiql": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/graphql-server-module-graphiql/-/graphql-server-module-graphiql-0.9.0.tgz", - "from": "graphql-server-module-graphiql@>=0.9.0 <0.10.0" + "from": "graphql@https://registry.npmjs.org/graphql/-/graphql-0.10.3.tgz" }, "graphql-subscriptions": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-0.4.4.tgz", - "from": "graphql-subscriptions@0.4.4" + "from": "graphql-subscriptions@https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-0.4.4.tgz" }, "graphql-tag": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.4.2.tgz", - "from": "graphql-tag@>=2.0.0 <3.0.0" + "from": "graphql-tag@https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.4.2.tgz" }, "graphql-tools": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-1.1.0.tgz", - "from": "graphql-tools@1.1.0" + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-1.2.2.tgz", + "from": "graphql-tools@https://registry.npmjs.org/graphql-tools/-/graphql-tools-1.2.2.tgz" }, "hoek": { "version": "2.16.3", "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", - "from": "hoek@>=2.0.0 <3.0.0" + "from": "hoek@https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz" }, "http-errors": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", - "from": "http-errors@>=1.6.1 <1.7.0" + "from": "http-errors@https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz" }, "iconv-lite": { "version": "0.4.15", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.15.tgz", - "from": "iconv-lite@0.4.15" + "from": "iconv-lite@https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.15.tgz" }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "from": "inherits@2.0.3" + "from": "inherits@https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz" }, "ipaddr.js": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.4.0.tgz", - "from": "ipaddr.js@1.4.0" + "from": "ipaddr.js@https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.4.0.tgz" }, "isemail": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/isemail/-/isemail-1.2.0.tgz", - "from": "isemail@>=1.0.0 <2.0.0" + "from": "isemail@https://registry.npmjs.org/isemail/-/isemail-1.2.0.tgz" }, "iterall": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.1.1.tgz", - "from": "iterall@>=1.1.0 <2.0.0" + "from": "iterall@https://registry.npmjs.org/iterall/-/iterall-1.1.1.tgz" }, "joi": { "version": "6.10.1", "resolved": "https://registry.npmjs.org/joi/-/joi-6.10.1.tgz", - "from": "joi@>=6.10.1 <7.0.0" - }, - "js-tokens": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", - "from": "js-tokens@>=3.0.0 <4.0.0" + "from": "joi@https://registry.npmjs.org/joi/-/joi-6.10.1.tgz" }, "jsonwebtoken": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.2.tgz", - "from": "jsonwebtoken@>=7.2.1 <8.0.0" + "version": "7.4.3", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.3.tgz", + "from": "jsonwebtoken@https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.3.tgz" }, "jwa": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz", - "from": "jwa@>=1.1.4 <2.0.0" + "from": "jwa@https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz" }, "jws": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/jws/-/jws-3.1.4.tgz", - "from": "jws@>=3.1.4 <4.0.0" + "from": "jws@https://registry.npmjs.org/jws/-/jws-3.1.4.tgz" }, "jwt-decode": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz", - "from": "jwt-decode@>=2.1.0 <3.0.0" + "from": "jwt-decode@https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz" + }, + "kamilkisiela-graphql-api": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/kamilkisiela-graphql-api/-/kamilkisiela-graphql-api-0.1.1.tgz", + "from": "kamilkisiela-graphql-api@https://registry.npmjs.org/kamilkisiela-graphql-api/-/kamilkisiela-graphql-api-0.1.1.tgz" + }, + "kamilkisiela-merge-graphql-schemas": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/kamilkisiela-merge-graphql-schemas/-/kamilkisiela-merge-graphql-schemas-1.1.2.tgz", + "from": "kamilkisiela-merge-graphql-schemas@https://registry.npmjs.org/kamilkisiela-merge-graphql-schemas/-/kamilkisiela-merge-graphql-schemas-1.1.2.tgz" }, "lodash": { "version": "4.17.4", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", - "from": "lodash@>=4.16.4 <5.0.0" - }, - "lodash-es": { - "version": "4.17.4", - "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.4.tgz", - "from": "lodash-es@>=4.2.1 <5.0.0" + "from": "lodash@https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz" }, "lodash.assign": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz", - "from": "lodash.assign@>=4.2.0 <5.0.0" + "from": "lodash.assign@https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz" }, "lodash.isobject": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/lodash.isobject/-/lodash.isobject-3.0.2.tgz", - "from": "lodash.isobject@>=3.0.2 <4.0.0" + "from": "lodash.isobject@https://registry.npmjs.org/lodash.isobject/-/lodash.isobject-3.0.2.tgz" }, "lodash.isstring": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", - "from": "lodash.isstring@>=4.0.1 <5.0.0" + "from": "lodash.isstring@https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz" }, "lodash.once": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", - "from": "lodash.once@>=4.0.0 <5.0.0" - }, - "loose-envify": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz", - "from": "loose-envify@>=1.1.0 <2.0.0" + "from": "lodash.once@https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz" }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "from": "media-typer@0.3.0" + "from": "media-typer@https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz" }, "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "from": "merge-descriptors@1.0.1" + "from": "merge-descriptors@https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz" }, - "merge-graphql-schemas": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/merge-graphql-schemas/-/merge-graphql-schemas-1.1.0.tgz", - "from": "merge-graphql-schemas@1.1.0" + "meteor-promise": { + "version": "0.8.6", + "resolved": "https://registry.npmjs.org/meteor-promise/-/meteor-promise-0.8.6.tgz", + "from": "meteor-promise@https://registry.npmjs.org/meteor-promise/-/meteor-promise-0.8.6.tgz" }, "methods": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "from": "methods@>=1.1.2 <1.2.0" + "from": "methods@https://registry.npmjs.org/methods/-/methods-1.1.2.tgz" }, "mime": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz", - "from": "mime@1.3.4" + "from": "mime@https://registry.npmjs.org/mime/-/mime-1.3.4.tgz" }, "mime-db": { "version": "1.29.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.29.0.tgz", - "from": "mime-db@>=1.29.0 <1.30.0" + "from": "mime-db@https://registry.npmjs.org/mime-db/-/mime-db-1.29.0.tgz" }, "mime-types": { "version": "2.1.16", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.16.tgz", - "from": "mime-types@>=2.1.15 <2.2.0" + "from": "mime-types@https://registry.npmjs.org/mime-types/-/mime-types-2.1.16.tgz" }, "moment": { "version": "2.18.1", "resolved": "https://registry.npmjs.org/moment/-/moment-2.18.1.tgz", - "from": "moment@>=2.0.0 <3.0.0" + "from": "moment@https://registry.npmjs.org/moment/-/moment-2.18.1.tgz" }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "from": "ms@>=2.0.0 <3.0.0" + "from": "ms@https://registry.npmjs.org/ms/-/ms-2.0.0.tgz" }, "negotiator": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", - "from": "negotiator@0.6.1" + "from": "negotiator@https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz" }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "from": "object-assign@>=4.0.0 <5.0.0" + "from": "object-assign@https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz" }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "from": "on-finished@>=2.3.0 <2.4.0" + "from": "on-finished@https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz" }, "parseurl": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.1.tgz", - "from": "parseurl@>=1.3.1 <1.4.0" + "from": "parseurl@https://registry.npmjs.org/parseurl/-/parseurl-1.3.1.tgz" }, "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "from": "path-to-regexp@0.1.7" + "from": "path-to-regexp@https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz" }, "proxy-addr": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.5.tgz", - "from": "proxy-addr@>=1.1.4 <1.2.0" + "from": "proxy-addr@https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.5.tgz" }, "qs": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz", - "from": "qs@6.4.0" + "from": "qs@https://registry.npmjs.org/qs/-/qs-6.4.0.tgz" }, "range-parser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", - "from": "range-parser@>=1.2.0 <1.3.0" + "from": "range-parser@https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz" }, "raw-body": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.2.0.tgz", - "from": "raw-body@>=2.2.0 <2.3.0" - }, - "redux": { - "version": "3.7.2", - "resolved": "https://registry.npmjs.org/redux/-/redux-3.7.2.tgz", - "from": "redux@>=3.4.0 <4.0.0" + "from": "raw-body@https://registry.npmjs.org/raw-body/-/raw-body-2.2.0.tgz" }, "regenerator-runtime": { - "version": "0.10.5", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", - "from": "regenerator-runtime@>=0.10.0 <0.11.0" + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz", + "from": "regenerator-runtime@https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz" }, "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "from": "safe-buffer@>=5.0.1 <6.0.0" + "from": "safe-buffer@https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz" }, "send": { - "version": "0.15.3", - "resolved": "https://registry.npmjs.org/send/-/send-0.15.3.tgz", - "from": "send@0.15.3" + "version": "0.15.4", + "resolved": "https://registry.npmjs.org/send/-/send-0.15.4.tgz", + "from": "send@https://registry.npmjs.org/send/-/send-0.15.4.tgz", + "dependencies": { + "debug": { + "version": "2.6.8", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", + "from": "debug@https://registry.npmjs.org/debug/-/debug-2.6.8.tgz" + } + } }, "serve-static": { - "version": "1.12.3", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.12.3.tgz", - "from": "serve-static@1.12.3" + "version": "1.12.4", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.12.4.tgz", + "from": "serve-static@https://registry.npmjs.org/serve-static/-/serve-static-1.12.4.tgz" }, "setprototypeof": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", - "from": "setprototypeof@1.0.3" + "from": "setprototypeof@https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz" }, "statuses": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", - "from": "statuses@>=1.3.1 <2.0.0" + "from": "statuses@https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz" }, "subscriptions-transport-ws": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/subscriptions-transport-ws/-/subscriptions-transport-ws-0.8.1.tgz", - "from": "subscriptions-transport-ws@0.8.1" + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/subscriptions-transport-ws/-/subscriptions-transport-ws-0.8.2.tgz", + "from": "subscriptions-transport-ws@https://registry.npmjs.org/subscriptions-transport-ws/-/subscriptions-transport-ws-0.8.2.tgz" }, "symbol-observable": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.4.tgz", - "from": "symbol-observable@>=1.0.2 <2.0.0" + "from": "symbol-observable@https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.4.tgz" }, "topo": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/topo/-/topo-1.1.0.tgz", - "from": "topo@>=1.0.0 <2.0.0" + "from": "topo@https://registry.npmjs.org/topo/-/topo-1.1.0.tgz" }, "type-is": { "version": "1.6.15", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", - "from": "type-is@>=1.6.15 <1.7.0" + "from": "type-is@https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz" }, "ultron": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.0.tgz", - "from": "ultron@>=1.1.0 <1.2.0" + "from": "ultron@https://registry.npmjs.org/ultron/-/ultron-1.1.0.tgz" }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "from": "unpipe@1.0.0" + "from": "unpipe@https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz" }, "utils-merge": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz", - "from": "utils-merge@1.0.0" + "from": "utils-merge@https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz" }, "uuid": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", - "from": "uuid@>=3.0.1 <4.0.0" + "from": "uuid@https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz" }, "vary": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.1.tgz", - "from": "vary@>=1.0.0 <2.0.0" - }, - "whatwg-fetch": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", - "from": "whatwg-fetch@>=2.0.0 <3.0.0" + "from": "vary@https://registry.npmjs.org/vary/-/vary-1.1.1.tgz" }, "ws": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/ws/-/ws-3.1.0.tgz", - "from": "ws@>=3.0.0 <4.0.0" + "from": "ws@https://registry.npmjs.org/ws/-/ws-3.1.0.tgz" }, "xtend": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "from": "xtend@>=4.0.1 <5.0.0" + "from": "xtend@https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz" } } } diff --git a/packages/rocketchat-graphql/README.md b/packages/rocketchat-graphql/README.md new file mode 100644 index 000000000000..712c36fd39ae --- /dev/null +++ b/packages/rocketchat-graphql/README.md @@ -0,0 +1,3 @@ +# rocketchat:graphql + +GraphQL API diff --git a/packages/rocketchat-graphql/package.js b/packages/rocketchat-graphql/package.js index b4ceb319ed9b..def84c4c84c9 100644 --- a/packages/rocketchat-graphql/package.js +++ b/packages/rocketchat-graphql/package.js @@ -12,14 +12,15 @@ Package.onUse(function(api) { 'http', 'rocketchat:lib', 'rocketchat:api', - 'rocketchat:accounts' + 'rocketchat:accounts', + 'swydo:graphql' ]); api.mainModule('server/api.js', 'server'); }); Npm.depends({ - '@accounts/graphql-api': '0.1.1', + 'kamilkisiela-graphql-api': '0.1.1', 'apollo-server-express': '1.1.2', 'cors': '2.8.4', 'body-parser': '1.17.2', @@ -27,6 +28,6 @@ Npm.depends({ 'graphql': '0.10.3', 'graphql-subscriptions': '0.4.4', 'graphql-tools': '1.2.2', - 'merge-graphql-schemas': '1.1.2', + 'kamilkisiela-merge-graphql-schemas': '1.1.2', 'subscriptions-transport-ws': '0.8.2' }); diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index a8262a0d33f4..9c1f36c00a90 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -1,5 +1,5 @@ import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'; -import { JSAccountsContext as jsAccountsContext } from '@accounts/graphql-api'; +import { JSAccountsContext as jsAccountsContext } from 'kamilkisiela-graphql-api'; import { SubscriptionServer } from 'subscriptions-transport-ws'; import { execute, subscribe } from 'graphql'; import { Meteor } from 'meteor/meteor'; diff --git a/packages/rocketchat-graphql/server/helpers/authenticated.js b/packages/rocketchat-graphql/server/helpers/authenticated.js index a0a39e676560..c36223b94b5a 100644 --- a/packages/rocketchat-graphql/server/helpers/authenticated.js +++ b/packages/rocketchat-graphql/server/helpers/authenticated.js @@ -1,6 +1,6 @@ import { AccountsServer } from 'meteor/rocketchat:accounts'; //import { authenticated as _authenticated } from '@accounts/graphql-api'; - +// import { authenticated as _authenticated } from 'kamilkisiela-graphql-api'; import { authenticated as _authenticated } from '../mocks/accounts/graphql-api'; export const authenticated = (resolver) => { diff --git a/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js b/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js index adbaaaa71d7e..8bd3dde10230 100644 --- a/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js +++ b/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js @@ -1,13 +1,3 @@ -/*export const authenticated = (Accounts, func) => (async(root, args, context, info) => { - const userObject = await Accounts.resumeSession(); - - if (userObject === null) { - throw new Error('Invalid or expired token!'); - } - - return await func(root, args, Object.assign(context, { user: userObject }), info); -});*/ - // Same as here: https://github.com/js-accounts/graphql/blob/master/packages/graphql-api/src/utils/authenticated-resolver.js // except code below works // It might be like that because of async/await, diff --git a/packages/rocketchat-graphql/server/mocks/accounts/server.js b/packages/rocketchat-graphql/server/mocks/accounts/server.js deleted file mode 100644 index 8bf64b3bccbf..000000000000 --- a/packages/rocketchat-graphql/server/mocks/accounts/server.js +++ /dev/null @@ -1,13 +0,0 @@ -const loggedOut = false; - -const AccountsServer = { - resumeSession: (async() => { - if (loggedOut) { - throw new Error('User not found'); - } - // User credentials - return RocketChat.models.Users.findOne({username: 'mys'}); - }) -}; - -export default AccountsServer; diff --git a/packages/rocketchat-graphql/server/resolvers/accounts/OauthProvider-type.js b/packages/rocketchat-graphql/server/resolvers/accounts/OauthProvider-type.js new file mode 100644 index 000000000000..fd13e7f61106 --- /dev/null +++ b/packages/rocketchat-graphql/server/resolvers/accounts/OauthProvider-type.js @@ -0,0 +1,5 @@ +import schema from '../../schemas/accounts/OauthProvider-type.graphql'; + +export { + schema +}; diff --git a/packages/rocketchat-graphql/server/schemas/accounts/index.js b/packages/rocketchat-graphql/server/resolvers/accounts/index.js similarity index 76% rename from packages/rocketchat-graphql/server/schemas/accounts/index.js rename to packages/rocketchat-graphql/server/resolvers/accounts/index.js index e82a7077059b..57d98cce5962 100644 --- a/packages/rocketchat-graphql/server/schemas/accounts/index.js +++ b/packages/rocketchat-graphql/server/resolvers/accounts/index.js @@ -1,6 +1,6 @@ -import { createJSAccountsGraphQL } from '@accounts/graphql-api'; +import { createJSAccountsGraphQL } from 'kamilkisiela-graphql-api'; import { AccountsServer } from 'meteor/rocketchat:accounts'; -import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; +import { mergeTypes, mergeResolvers } from 'kamilkisiela-merge-graphql-schemas'; // queries import * as oauthProviders from './oauthProviders'; diff --git a/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.js b/packages/rocketchat-graphql/server/resolvers/accounts/oauthProviders.js similarity index 80% rename from packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.js rename to packages/rocketchat-graphql/server/resolvers/accounts/oauthProviders.js index 9cefedb7a15e..0cccbc9381d9 100644 --- a/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.js +++ b/packages/rocketchat-graphql/server/resolvers/accounts/oauthProviders.js @@ -1,6 +1,8 @@ import { HTTP } from 'meteor/http'; import { Meteor } from 'meteor/meteor'; +import schema from '../../schemas/accounts/oauthProviders.graphql'; + function isJSON(obj) { try { JSON.parse(obj); @@ -10,13 +12,7 @@ function isJSON(obj) { } } -export const schema = ` - type Query { - oauthProviders: [OauthProvider] - } -`; - -export const resolver = { +const resolver = { Query: { oauthProviders: async() => { // depends on rocketchat:grant package @@ -31,9 +27,13 @@ export const resolver = { throw new Error('Could not parse the result'); } } catch (e) { - console.error('oauthProviders resolver', e); throw new Error('rocketchat:grant not installed'); } } } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js b/packages/rocketchat-graphql/server/resolvers/channels/Channel-type.js similarity index 75% rename from packages/rocketchat-graphql/server/schemas/channels/Channel-type.js rename to packages/rocketchat-graphql/server/resolvers/channels/Channel-type.js index cfcbebe2a327..e4dfb9ba4371 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/Channel-type.js @@ -1,25 +1,7 @@ import { property } from '../../helpers/property'; +import schema from '../../schemas/channels/Channel-type.graphql'; -export const schema = ` - type Channel { - id: String! - name: String - description: String - announcement: String - topic: String - members: [User] - owners: [User] - numberOfMembers: Int - numberOfMessages: Int - readOnly: Boolean - direct: Boolean - privateChannel: Boolean - favourite: Boolean - unseenMessages: Int - } -`; - -export const resolver = { +const resolver = { Channel: { id: property('_id'), name: (root, args, { user }) => { @@ -59,3 +41,8 @@ export const resolver = { } } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/resolvers/channels/ChannelFilter-input.js b/packages/rocketchat-graphql/server/resolvers/channels/ChannelFilter-input.js new file mode 100644 index 000000000000..54c5be23b0ff --- /dev/null +++ b/packages/rocketchat-graphql/server/resolvers/channels/ChannelFilter-input.js @@ -0,0 +1,5 @@ +import schema from '../../schemas/channels/ChannelFilter-input.graphql'; + +export { + schema +}; diff --git a/packages/rocketchat-graphql/server/resolvers/channels/ChannelNameAndDirect-input.js b/packages/rocketchat-graphql/server/resolvers/channels/ChannelNameAndDirect-input.js new file mode 100644 index 000000000000..ad769ae36913 --- /dev/null +++ b/packages/rocketchat-graphql/server/resolvers/channels/ChannelNameAndDirect-input.js @@ -0,0 +1,5 @@ +import schema from '../../schemas/channels/ChannelNameAndDirect-input.graphql'; + +export { + schema +}; diff --git a/packages/rocketchat-graphql/server/resolvers/channels/ChannelSort-enum.js b/packages/rocketchat-graphql/server/resolvers/channels/ChannelSort-enum.js new file mode 100644 index 000000000000..3cd8b5f7b8d3 --- /dev/null +++ b/packages/rocketchat-graphql/server/resolvers/channels/ChannelSort-enum.js @@ -0,0 +1,5 @@ +import schema from '../../schemas/channels/ChannelSort-enum.graphql'; + +export { + schema +}; diff --git a/packages/rocketchat-graphql/server/resolvers/channels/Privacy-enum.js b/packages/rocketchat-graphql/server/resolvers/channels/Privacy-enum.js new file mode 100644 index 000000000000..bc0172b74adb --- /dev/null +++ b/packages/rocketchat-graphql/server/resolvers/channels/Privacy-enum.js @@ -0,0 +1,5 @@ +import schema from '../../schemas/channels/Privacy-enum.graphql'; + +export { + schema +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelByName.js b/packages/rocketchat-graphql/server/resolvers/channels/channelByName.js similarity index 73% rename from packages/rocketchat-graphql/server/schemas/channels/channelByName.js rename to packages/rocketchat-graphql/server/resolvers/channels/channelByName.js index 63b70ddf360e..060e2a2526a6 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channelByName.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/channelByName.js @@ -1,13 +1,8 @@ import { authenticated } from '../../helpers/authenticated'; import { roomPublicFields } from './settings'; +import schema from '../../schemas/channels/channelByName.graphql'; -export const schema = ` - type Query { - channelByName(name: String!): Channel - } -`; - -export const resolver = { +const resolver = { Query: { channelByName: authenticated((root, { name }) => { const query = { @@ -21,3 +16,8 @@ export const resolver = { }) } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/channels.js b/packages/rocketchat-graphql/server/resolvers/channels/channels.js similarity index 80% rename from packages/rocketchat-graphql/server/schemas/channels/channels.js rename to packages/rocketchat-graphql/server/resolvers/channels/channels.js index c188819c96b3..6087771b86fd 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channels.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/channels.js @@ -1,17 +1,8 @@ import { authenticated } from '../../helpers/authenticated'; import { roomPublicFields } from './settings'; +import schema from '../../schemas/channels/channels.graphql'; -export const schema = ` - type Query { - channels(filter: ChannelFilter = { - privacy: ALL, - joinedChannels: false, - sortBy: NAME - }): [Channel] - } -`; - -export const resolver = { +const resolver = { Query: { channels: authenticated((root, args) => { const query = {}; @@ -49,12 +40,15 @@ export const resolver = { }; break; } - - // joinedChannels - // TODO: } return RocketChat.models.Rooms.find(query, options).fetch(); }) } }; + + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js b/packages/rocketchat-graphql/server/resolvers/channels/channelsByUser.js similarity index 78% rename from packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js rename to packages/rocketchat-graphql/server/resolvers/channels/channelsByUser.js index 0784da1854a0..29a240e5c000 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/channelsByUser.js @@ -1,20 +1,13 @@ import { authenticated } from '../../helpers/authenticated'; - import { roomPublicFields } from './settings'; +import schema from '../../schemas/channels/channelsByUser.graphql'; -export const schema = ` - type Query { - channelsByUser(userId: String!): [Channel] - } -`; - -export const resolver = { +const resolver = { Query: { channelsByUser: authenticated((root, { userId }) => { const user = RocketChat.models.Users.findOneById(userId); if (!user) { - // TODO: throw new Error('No user'); } @@ -29,3 +22,8 @@ export const resolver = { }) } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/resolvers/channels/createChannel.js b/packages/rocketchat-graphql/server/resolvers/channels/createChannel.js new file mode 100644 index 000000000000..e0f8a84d6a3d --- /dev/null +++ b/packages/rocketchat-graphql/server/resolvers/channels/createChannel.js @@ -0,0 +1,38 @@ +import { authenticated } from '../../helpers/authenticated'; +import schema from '../../schemas/channels/createChannel.graphql'; + +const resolver = { + Mutation: { + createChannel: authenticated((root, args, { user }) => { + try { + RocketChat.API.channels.create.validate({ + user: { + value: user._id + }, + name: { + value: args.name, + key: 'name' + }, + members: { + value: args.membersId, + key: 'membersId' + } + }); + } catch (e) { + throw e; + } + + const { channel } = RocketChat.API.channels.create.execute(user._id, { + name: args.name, + members: args.membersId + }); + + return channel; + }) + } +}; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/directChannel.js b/packages/rocketchat-graphql/server/resolvers/channels/directChannel.js similarity index 84% rename from packages/rocketchat-graphql/server/schemas/channels/directChannel.js rename to packages/rocketchat-graphql/server/resolvers/channels/directChannel.js index e2431551e811..2218cdf7837b 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/directChannel.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/directChannel.js @@ -1,13 +1,8 @@ import { authenticated } from '../../helpers/authenticated'; import { roomPublicFields } from './settings'; +import schema from '../../schemas/channels/directChannel.graphql'; -export const schema = ` - type Query { - directChannel(username: String, channelId: String): Channel - } -`; - -export const resolver = { +const resolver = { Query: { directChannel: authenticated((root, { username, channelId }, { user }) => { const query = { @@ -19,6 +14,7 @@ export const resolver = { if (username === user.username) { throw new Error('You cannot specify your username'); } + query.usernames = { $all: [ user.username, username ] }; } else if (typeof channelId !== 'undefined') { query.id = channelId; @@ -32,3 +28,8 @@ export const resolver = { }) } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js b/packages/rocketchat-graphql/server/resolvers/channels/hideChannel.js similarity index 87% rename from packages/rocketchat-graphql/server/schemas/channels/hideChannel.js rename to packages/rocketchat-graphql/server/resolvers/channels/hideChannel.js index 2904ca9dcd2f..23cd1017f985 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/hideChannel.js @@ -1,14 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { authenticated } from '../../helpers/authenticated'; +import schema from '../../schemas/channels/hideChannel.graphql'; -export const schema = ` - type Mutation { - hideChannel(channelId: String!): Boolean - } -`; - -export const resolver = { +const resolver = { Mutation: { hideChannel: authenticated((root, args, { user }) => { const channel = RocketChat.models.Rooms.findOne({ @@ -38,3 +33,8 @@ export const resolver = { }) } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/index.js b/packages/rocketchat-graphql/server/resolvers/channels/index.js similarity index 93% rename from packages/rocketchat-graphql/server/schemas/channels/index.js rename to packages/rocketchat-graphql/server/resolvers/channels/index.js index 063e9da41804..82a9dbff107d 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/index.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/index.js @@ -1,4 +1,4 @@ -import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; +import { mergeTypes, mergeResolvers } from 'kamilkisiela-merge-graphql-schemas'; // queries import * as channels from './channels'; diff --git a/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js b/packages/rocketchat-graphql/server/resolvers/channels/leaveChannel.js similarity index 81% rename from packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js rename to packages/rocketchat-graphql/server/resolvers/channels/leaveChannel.js index 141f1eba171f..306beff5d7a6 100644 --- a/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/leaveChannel.js @@ -1,14 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { authenticated } from '../../helpers/authenticated'; +import schema from '../../schemas/channels/leaveChannel.graphql'; -export const schema = ` - type Mutation { - leaveChannel(channelId: String!): Boolean - } -`; - -export const resolver = { +const resolver = { Mutation: { leaveChannel: authenticated((root, args, { user }) => { const channel = RocketChat.models.Rooms.findOne({ @@ -28,3 +23,8 @@ export const resolver = { }) } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/channels/settings.js b/packages/rocketchat-graphql/server/resolvers/channels/settings.js similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/settings.js rename to packages/rocketchat-graphql/server/resolvers/channels/settings.js diff --git a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js b/packages/rocketchat-graphql/server/resolvers/messages/Message-type.js similarity index 78% rename from packages/rocketchat-graphql/server/schemas/messages/Message-type.js rename to packages/rocketchat-graphql/server/resolvers/messages/Message-type.js index 264ef427390b..0fc8c6c36bb4 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/Message-type.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/Message-type.js @@ -1,25 +1,8 @@ import { property } from '../../helpers/property'; import { dateToFloat } from '../../helpers/dateToFloat'; +import schema from '../../schemas/messages/Message-type.graphql'; -export const schema = ` - type Message { - id: String - author: User - content: String - channel: Channel - creationTime: Float - # Message sent by server e.g. User joined channel - fromServer: Boolean - type: String - # List of mentioned users - userRef: [User] - # list of mentioned channels - channelRef: [Channel] - reactions: [Reaction] - } -`; - -export const resolver = { +const resolver = { Message: { id: property('_id'), content: property('msg'), @@ -84,3 +67,8 @@ export const resolver = { } } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/resolvers/messages/MessageIdentifier-input.js b/packages/rocketchat-graphql/server/resolvers/messages/MessageIdentifier-input.js new file mode 100644 index 000000000000..63f5a8bbb300 --- /dev/null +++ b/packages/rocketchat-graphql/server/resolvers/messages/MessageIdentifier-input.js @@ -0,0 +1,5 @@ +import schema from '../../schemas/messages/MessageIdentifier-input.graphql'; + +export { + schema +}; diff --git a/packages/rocketchat-graphql/server/resolvers/messages/MessagesWithCursor-type.js b/packages/rocketchat-graphql/server/resolvers/messages/MessagesWithCursor-type.js new file mode 100644 index 000000000000..e25dfb592f7a --- /dev/null +++ b/packages/rocketchat-graphql/server/resolvers/messages/MessagesWithCursor-type.js @@ -0,0 +1,5 @@ +import schema from '../../schemas/messages/MessagesWithCursor-type.graphql'; + +export { + schema +}; diff --git a/packages/rocketchat-graphql/server/resolvers/messages/Reaction-type.js b/packages/rocketchat-graphql/server/resolvers/messages/Reaction-type.js new file mode 100644 index 000000000000..81ec44c5b9b8 --- /dev/null +++ b/packages/rocketchat-graphql/server/resolvers/messages/Reaction-type.js @@ -0,0 +1,5 @@ +import schema from '../../schemas/messages/Reaction-type.graphql'; + +export { + schema +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js b/packages/rocketchat-graphql/server/resolvers/messages/addReactionToMessage.js similarity index 74% rename from packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js rename to packages/rocketchat-graphql/server/resolvers/messages/addReactionToMessage.js index 2dc894969880..1c915d3a4c9a 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/addReactionToMessage.js @@ -1,14 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { authenticated } from '../../helpers/authenticated'; +import schema from '../../schemas/messages/addReactionToMessage.graphql'; -export const schema = ` - type Mutation { - addReactionToMassage(id: MessageIdentifier!, icon: String!): Message - } -`; - -export const resolver = { +const resolver = { Mutation: { addReactionToMassage: authenticated((root, { id, icon }, { user }) => { return new Promise((resolve) => { @@ -21,3 +16,8 @@ export const resolver = { }) } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.js b/packages/rocketchat-graphql/server/resolvers/messages/chatMessageAdded.js similarity index 83% rename from packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.js rename to packages/rocketchat-graphql/server/resolvers/messages/chatMessageAdded.js index 0f127c3c934f..dfbb818e12b2 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/chatMessageAdded.js @@ -1,6 +1,7 @@ import { withFilter } from 'graphql-subscriptions'; import { pubsub } from '../../subscriptions'; +import schema from '../../schemas/messages/chatMessageAdded.graphql'; export const CHAT_MESSAGE_SUBSCRIPTION_TOPIC = 'CHAT_MESSAGE_ADDED'; @@ -8,13 +9,7 @@ export function publishMessage(message) { pubsub.publish(CHAT_MESSAGE_SUBSCRIPTION_TOPIC, { chatMessageAdded: message }); } -export const schema = ` - type Subscription { - chatMessageAdded(channelId: String!): Message - } -`; - -export const resolver = { +const resolver = { Subscription: { chatMessageAdded: { subscribe: withFilter(() => pubsub.asyncIterator(CHAT_MESSAGE_SUBSCRIPTION_TOPIC), (payload, args) => { @@ -27,3 +22,8 @@ export const resolver = { RocketChat.callbacks.add('afterSaveMessage', (message) => { publishMessage(message); }, null, 'chatMessageAddedSubscription'); + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js b/packages/rocketchat-graphql/server/resolvers/messages/deleteMessage.js similarity index 83% rename from packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js rename to packages/rocketchat-graphql/server/resolvers/messages/deleteMessage.js index 91b3d0fa7e92..851767060869 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/deleteMessage.js @@ -1,14 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { authenticated } from '../../helpers/authenticated'; +import schema from '../../schemas/messages/deleteMessage.graphql'; -export const schema = ` - type Mutation { - deleteMessage(id: MessageIdentifier!): Message - } -`; - -export const resolver = { +const resolver = { Mutation: { deleteMessage: authenticated((root, { id }, { user }) => { const msg = RocketChat.models.Messages.findOneById(id.messageId, { fields: { u: 1, rid: 1 }}); @@ -29,3 +24,8 @@ export const resolver = { }) } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/editMessage.js b/packages/rocketchat-graphql/server/resolvers/messages/editMessage.js similarity index 85% rename from packages/rocketchat-graphql/server/schemas/messages/editMessage.js rename to packages/rocketchat-graphql/server/resolvers/messages/editMessage.js index da1e1c8e850e..42973929e23a 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/editMessage.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/editMessage.js @@ -1,14 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { authenticated } from '../../helpers/authenticated'; +import schema from '../../schemas/messages/editMessage.graphql'; -export const schema = ` - type Mutation { - editMessage(id: MessageIdentifier!, content: String!): Message - } -`; - -export const resolver = { +const resolver = { Mutation: { editMessage: authenticated((root, { id, content }, { user }) => { const msg = RocketChat.models.Messages.findOneById(id.messageId); @@ -31,3 +26,8 @@ export const resolver = { }) } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/index.js b/packages/rocketchat-graphql/server/resolvers/messages/index.js similarity index 93% rename from packages/rocketchat-graphql/server/schemas/messages/index.js rename to packages/rocketchat-graphql/server/resolvers/messages/index.js index fb9728b19815..ad5fc67076e6 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/index.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/index.js @@ -1,4 +1,4 @@ -import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; +import { mergeTypes, mergeResolvers } from 'kamilkisiela-merge-graphql-schemas'; // queries import * as messages from './messages'; diff --git a/packages/rocketchat-graphql/server/schemas/messages/messages.js b/packages/rocketchat-graphql/server/resolvers/messages/messages.js similarity index 66% rename from packages/rocketchat-graphql/server/schemas/messages/messages.js rename to packages/rocketchat-graphql/server/resolvers/messages/messages.js index 8083d2fa6fdf..6ef4b7502591 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/messages.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/messages.js @@ -1,20 +1,7 @@ import { authenticated } from '../../helpers/authenticated'; +import schema from '../../schemas/messages/messages.graphql'; -export const schema = ` - type Query { - messages( - channelId: String, - channelDetails: ChannelNameAndDirect, - channelName: String, - cursor: String, - count: Int, - searchRegex: String, - excludeServer: Boolean - ): MessagesWithCursor - } -`; - -export const resolver = { +const resolver = { Query: { messages: authenticated((root, args) => { const messagesQuery = {}; @@ -45,10 +32,10 @@ export const resolver = { // cursor if (isPagination && args.cursor) { const cursorMsg = RocketChat.models.Messages.findOne(args.cursor, { fields: { ts: 1 } }); - messagesQuery.ts = { $gt: cursorMsg.ts }; + messagesQuery.ts = { $lt: cursorMsg.ts }; } - // searchRegex + // search if (typeof args.searchRegex === 'string') { messagesQuery.msg = { $regex: new RegExp(args.searchRegex, 'i') @@ -60,19 +47,26 @@ export const resolver = { messagesOptions.limit = args.count; } + // exclude messages generated by server if (args.excludeServer === true) { messagesQuery.t = { $exists: false }; } - const messages = RocketChat.models.Messages.find( - Object.assign({}, messagesQuery, { rid: channel._id }), - messagesOptions - ); + // look for messages that belongs to specific channel + messagesQuery.rid = channel._id; + + const messages = RocketChat.models.Messages.find(messagesQuery, messagesOptions); messagesArray = messages.fetch(); if (isPagination) { - cursor = (messagesArray[messagesArray.length - 1] || {})._id; + // oldest first (because of findOne) + messagesOptions.sort.ts = 1; + + const firstMessage = RocketChat.models.Messages.findOne(messagesQuery, messagesOptions); + const lastId = (messagesArray[messagesArray.length - 1] || {})._id; + + cursor = !lastId || lastId === firstMessage._id ? null : lastId; } } @@ -84,3 +78,8 @@ export const resolver = { }) } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js b/packages/rocketchat-graphql/server/resolvers/messages/sendMessage.js similarity index 75% rename from packages/rocketchat-graphql/server/schemas/messages/sendMessage.js rename to packages/rocketchat-graphql/server/resolvers/messages/sendMessage.js index 430460b72de8..c0930382578b 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/sendMessage.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/sendMessage.js @@ -1,14 +1,9 @@ /* global processWebhookMessage */ import { authenticated } from '../../helpers/authenticated'; +import schema from '../../schemas/messages/sendMessage.graphql'; -export const schema = ` - type Mutation { - sendMessage(channelId: String!, content: String!): Message - } -`; - -export const resolver = { +const resolver = { Mutation: { sendMessage: authenticated((root, { channelId, content }, { user }) => { const messageReturn = processWebhookMessage({ @@ -24,3 +19,8 @@ export const resolver = { }) } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schemas/users/User-type.js b/packages/rocketchat-graphql/server/resolvers/users/User-type.js similarity index 65% rename from packages/rocketchat-graphql/server/schemas/users/User-type.js rename to packages/rocketchat-graphql/server/resolvers/users/User-type.js index 3891f47e1d65..6eede62b43ef 100644 --- a/packages/rocketchat-graphql/server/schemas/users/User-type.js +++ b/packages/rocketchat-graphql/server/resolvers/users/User-type.js @@ -1,19 +1,7 @@ -import { - property -} from '../../helpers/property'; +import { property } from '../../helpers/property'; +import schema from '../../schemas/users/User-type.graphql'; -export const schema = ` - extend type User { - status: UserStatus - avatar: String - name: String - lastLogin: String - channels: [Channel] - directMessages: [Channel] - } -`; - -export const resolver = { +const resolver = { User: { id: property('_id'), status: ({status}) => status.toUpperCase(), @@ -34,3 +22,8 @@ export const resolver = { } } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/resolvers/users/UserStatus-enum.js b/packages/rocketchat-graphql/server/resolvers/users/UserStatus-enum.js new file mode 100644 index 000000000000..61c84d39a6e5 --- /dev/null +++ b/packages/rocketchat-graphql/server/resolvers/users/UserStatus-enum.js @@ -0,0 +1,5 @@ +import schema from '../../schemas/users/UserStatus-enum.graphql'; + +export { + schema +}; diff --git a/packages/rocketchat-graphql/server/schemas/users/index.js b/packages/rocketchat-graphql/server/resolvers/users/index.js similarity index 82% rename from packages/rocketchat-graphql/server/schemas/users/index.js rename to packages/rocketchat-graphql/server/resolvers/users/index.js index 7647d5a5fdd6..6de11371bf97 100644 --- a/packages/rocketchat-graphql/server/schemas/users/index.js +++ b/packages/rocketchat-graphql/server/resolvers/users/index.js @@ -1,4 +1,4 @@ -import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; +import { mergeTypes, mergeResolvers } from 'kamilkisiela-merge-graphql-schemas'; // mutations import * as setStatus from './setStatus'; diff --git a/packages/rocketchat-graphql/server/schemas/users/setStatus.js b/packages/rocketchat-graphql/server/resolvers/users/setStatus.js similarity index 73% rename from packages/rocketchat-graphql/server/schemas/users/setStatus.js rename to packages/rocketchat-graphql/server/resolvers/users/setStatus.js index 6c61f4675b77..6d6f4aca4902 100644 --- a/packages/rocketchat-graphql/server/schemas/users/setStatus.js +++ b/packages/rocketchat-graphql/server/resolvers/users/setStatus.js @@ -1,12 +1,7 @@ import { authenticated } from '../../helpers/authenticated'; +import schema from '../../schemas/users/setStatus.graphql'; -export const schema = ` - type Mutation { - setStatus(status: UserStatus!): User - } -`; - -export const resolver = { +const resolver = { Mutation: { setStatus: authenticated((root, { status }, { user }) => { RocketChat.models.Users.update(user._id, { @@ -19,3 +14,8 @@ export const resolver = { }) } }; + +export { + schema, + resolver +}; diff --git a/packages/rocketchat-graphql/server/schema.js b/packages/rocketchat-graphql/server/schema.js index 3ee5b41532fa..1cbf6c38eeac 100644 --- a/packages/rocketchat-graphql/server/schema.js +++ b/packages/rocketchat-graphql/server/schema.js @@ -1,13 +1,10 @@ -import { - makeExecutableSchema -} from 'graphql-tools'; +import { makeExecutableSchema } from 'graphql-tools'; +import { mergeTypes, mergeResolvers } from 'kamilkisiela-merge-graphql-schemas'; -import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; - -import * as channels from './schemas/channels'; -import * as messages from './schemas/messages'; -import * as accounts from './schemas/accounts'; -import * as users from './schemas/users'; +import * as channels from './resolvers/channels'; +import * as messages from './resolvers/messages'; +import * as accounts from './resolvers/accounts'; +import * as users from './resolvers/users'; const schema = mergeTypes([ channels.schema, diff --git a/packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.graphql b/packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.graphql new file mode 100644 index 000000000000..0bdf1ed7e00b --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.graphql @@ -0,0 +1,4 @@ +type LoginResult { + accessToken: String! + refreshToken: String! +} diff --git a/packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.js b/packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.js deleted file mode 100644 index 4a0a7c8397b4..000000000000 --- a/packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.js +++ /dev/null @@ -1,6 +0,0 @@ -export const schema = ` - type LoginResult { - accessToken: String! - refreshToken: String! - } -`; diff --git a/packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.graphql b/packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.graphql new file mode 100644 index 000000000000..c91fe5e6379a --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.graphql @@ -0,0 +1,3 @@ +type OauthProvider { + name: String! +} diff --git a/packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.js b/packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.js deleted file mode 100644 index dd4a4253fd37..000000000000 --- a/packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.js +++ /dev/null @@ -1,5 +0,0 @@ -export const schema = ` - type OauthProvider { - name: String! - } -`; diff --git a/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.graphql b/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.graphql new file mode 100644 index 000000000000..9ba76de8adb8 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.graphql @@ -0,0 +1,3 @@ +type Query { + oauthProviders: [OauthProvider] +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.graphql b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.graphql new file mode 100644 index 000000000000..03c4557918df --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.graphql @@ -0,0 +1,16 @@ +type Channel { + id: String! + name: String + description: String + announcement: String + topic: String + members: [User] + owners: [User] + numberOfMembers: Int + numberOfMessages: Int + readOnly: Boolean + direct: Boolean + privateChannel: Boolean + favourite: Boolean + unseenMessages: Int +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.graphql b/packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.graphql new file mode 100644 index 000000000000..a00850e371cc --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.graphql @@ -0,0 +1,6 @@ +input ChannelFilter { + nameFilter: String + privacy: Privacy + joinedChannels: Boolean + sortBy: ChannelSort +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.js b/packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.js deleted file mode 100644 index b80d4c680a95..000000000000 --- a/packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.js +++ /dev/null @@ -1,8 +0,0 @@ -export const schema = ` - input ChannelFilter { - nameFilter: String - privacy: Privacy - joinedChannels: Boolean - sortBy: ChannelSort - } -`; diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.graphql b/packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.graphql new file mode 100644 index 000000000000..139567e862e9 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.graphql @@ -0,0 +1,4 @@ +input ChannelNameAndDirect { + name: String! + direct: Boolean! +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.js b/packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.js deleted file mode 100644 index f3bbda3125d1..000000000000 --- a/packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.js +++ /dev/null @@ -1,6 +0,0 @@ -export const schema = ` - input ChannelNameAndDirect { - name: String! - direct: Boolean! - } -`; diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.graphql b/packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.graphql new file mode 100644 index 000000000000..8a2c2902e6db --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.graphql @@ -0,0 +1,4 @@ +enum ChannelSort { + NAME + NUMBER_OF_MESSAGES +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.js b/packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.js deleted file mode 100644 index beecdedd89ef..000000000000 --- a/packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.js +++ /dev/null @@ -1,6 +0,0 @@ -export const schema = ` - enum ChannelSort { - NAME - NUMBER_OF_MESSAGES - } -`; diff --git a/packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.graphql b/packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.graphql new file mode 100644 index 000000000000..f28a57d51c28 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.graphql @@ -0,0 +1,5 @@ +enum Privacy { + PRIVATE + PUBLIC + ALL +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.js b/packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.js deleted file mode 100644 index d0cd977a9470..000000000000 --- a/packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.js +++ /dev/null @@ -1,7 +0,0 @@ -export const schema = ` - enum Privacy { - PRIVATE - PUBLIC - ALL - } -`; diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelByName.graphql b/packages/rocketchat-graphql/server/schemas/channels/channelByName.graphql new file mode 100644 index 000000000000..e301ce38f7f6 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/channelByName.graphql @@ -0,0 +1,3 @@ +type Query { + channelByName(name: String!): Channel +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/channels.graphql b/packages/rocketchat-graphql/server/schemas/channels/channels.graphql new file mode 100644 index 000000000000..6e4ac5608249 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/channels.graphql @@ -0,0 +1,7 @@ +type Query { + channels(filter: ChannelFilter = { + privacy: ALL, + joinedChannels: false, + sortBy: NAME + }): [Channel] +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.graphql b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.graphql new file mode 100644 index 000000000000..8dfe20a071c5 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.graphql @@ -0,0 +1,3 @@ +type Query { + channelsByUser(userId: String!): [Channel] +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/createChannel.graphql b/packages/rocketchat-graphql/server/schemas/channels/createChannel.graphql new file mode 100644 index 000000000000..85317c86603a --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/createChannel.graphql @@ -0,0 +1,8 @@ +type Mutation { + createChannel( + name: String!, + private: Boolean = false, + readOnly: Boolean = false, + membersId: [String!] + ): Channel +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/createChannel.js b/packages/rocketchat-graphql/server/schemas/channels/createChannel.js deleted file mode 100644 index c87e88991767..000000000000 --- a/packages/rocketchat-graphql/server/schemas/channels/createChannel.js +++ /dev/null @@ -1,45 +0,0 @@ -import { Meteor } from 'meteor/meteor'; - -import { authenticated } from '../../helpers/authenticated'; - -export const schema = ` - type Mutation { - createChannel( - name: String!, - private: Boolean = false, - readOnly: Boolean = false, - membersId: [String!] - ): Channel - } -`; - -export const resolver = { - Mutation: { - createChannel: authenticated((root, args, { user }) => { - if (!RocketChat.authz.hasPermission(user._id, 'create-c')) { - return RocketChat.API.v1.unauthorized(); - } - - if (!args.name) { - throw new Error('Param "name" is required'); - } - - if (args.membersId && !_.isArray(args.membersId)) { - throw new Error('Param "membersId" must be an array if provided'); - } - - let readOnly = false; - if (typeof args.readOnly !== 'undefined') { - readOnly = args.readOnly; - } - - let id; - Meteor.runAsUser(user._id, () => { - id = Meteor.call('createChannel', args.name, args.membersId ? args.membersId : [], readOnly); - }); - - return RocketChat.models.Rooms.findOneById(id.rid, { fields: RocketChat.API.v1.defaultFieldsToExclude }); - }) - } -}; - diff --git a/packages/rocketchat-graphql/server/schemas/channels/directChannel.graphql b/packages/rocketchat-graphql/server/schemas/channels/directChannel.graphql new file mode 100644 index 000000000000..4e41994bce80 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/directChannel.graphql @@ -0,0 +1,3 @@ +type Query { + directChannel(username: String, channelId: String): Channel +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.graphql b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.graphql new file mode 100644 index 000000000000..5ea9517f5741 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.graphql @@ -0,0 +1,3 @@ +type Mutation { + hideChannel(channelId: String!): Boolean +} diff --git a/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.graphql b/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.graphql new file mode 100644 index 000000000000..e6ceb4075c4e --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.graphql @@ -0,0 +1,3 @@ +type Mutation { + leaveChannel(channelId: String!): Boolean +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/Message-type.graphql b/packages/rocketchat-graphql/server/schemas/messages/Message-type.graphql new file mode 100644 index 000000000000..8ccfdebfbf1d --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/Message-type.graphql @@ -0,0 +1,15 @@ +type Message { + id: String + author: User + content: String + channel: Channel + creationTime: Float + # Message sent by server e.g. User joined channel + fromServer: Boolean + type: String + # List of mentioned users + userRef: [User] + # list of mentioned channels + channelRef: [Channel] + reactions: [Reaction] +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.graphql b/packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.graphql new file mode 100644 index 000000000000..88fbe90711cf --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.graphql @@ -0,0 +1,4 @@ +input MessageIdentifier { + channelId: String! + messageId: String! +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.js b/packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.js deleted file mode 100644 index bb8571477bfe..000000000000 --- a/packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.js +++ /dev/null @@ -1,6 +0,0 @@ -export const schema = ` - input MessageIdentifier { - channelId: String! - messageId: String! - } -`; diff --git a/packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.graphql b/packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.graphql new file mode 100644 index 000000000000..e890725f6efb --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.graphql @@ -0,0 +1,5 @@ +type MessagesWithCursor { + cursor: String + channel: Channel + messagesArray: [Message] +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.js b/packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.js deleted file mode 100644 index b70b287321b8..000000000000 --- a/packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.js +++ /dev/null @@ -1,7 +0,0 @@ -export const schema = ` - type MessagesWithCursor { - cursor: String - channel: Channel - messagesArray: [Message] - } -`; diff --git a/packages/rocketchat-graphql/server/schemas/messages/Reaction-type.graphql b/packages/rocketchat-graphql/server/schemas/messages/Reaction-type.graphql new file mode 100644 index 000000000000..e6eedf75d1e1 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/Reaction-type.graphql @@ -0,0 +1,4 @@ +type Reaction { + username: String + icon: String +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/Reaction-type.js b/packages/rocketchat-graphql/server/schemas/messages/Reaction-type.js deleted file mode 100644 index c337f52ce6bf..000000000000 --- a/packages/rocketchat-graphql/server/schemas/messages/Reaction-type.js +++ /dev/null @@ -1,6 +0,0 @@ -export const schema = ` - type Reaction { - username: String - icon: String - } -`; diff --git a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphql b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphql new file mode 100644 index 000000000000..61c74c26c499 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphql @@ -0,0 +1,3 @@ +type Mutation { + addReactionToMassage(id: MessageIdentifier!, icon: String!): Message +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphql b/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphql new file mode 100644 index 000000000000..f88b2979ca5a --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphql @@ -0,0 +1,3 @@ +type Subscription { + chatMessageAdded(channelId: String!): Message +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.graphql b/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.graphql new file mode 100644 index 000000000000..f298a14ebf98 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.graphql @@ -0,0 +1,3 @@ +type Mutation { + deleteMessage(id: MessageIdentifier!): Message +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/editMessage.graphql b/packages/rocketchat-graphql/server/schemas/messages/editMessage.graphql new file mode 100644 index 000000000000..19900c58b272 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/editMessage.graphql @@ -0,0 +1,3 @@ +type Mutation { + editMessage(id: MessageIdentifier!, content: String!): Message +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/messages.graphql b/packages/rocketchat-graphql/server/schemas/messages/messages.graphql new file mode 100644 index 000000000000..2b9774942e76 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/messages.graphql @@ -0,0 +1,11 @@ +type Query { + messages( + channelId: String, + channelDetails: ChannelNameAndDirect, + channelName: String, + cursor: String, + count: Int, + searchRegex: String, + excludeServer: Boolean + ): MessagesWithCursor +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphql b/packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphql new file mode 100644 index 000000000000..6f160fef1c94 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphql @@ -0,0 +1,3 @@ +type Mutation { + sendMessage(channelId: String!, content: String!): Message +} diff --git a/packages/rocketchat-graphql/server/schemas/users/User-type.graphql b/packages/rocketchat-graphql/server/schemas/users/User-type.graphql new file mode 100644 index 000000000000..2a345415227e --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/users/User-type.graphql @@ -0,0 +1,8 @@ +extend type User { + status: UserStatus + avatar: String + name: String + lastLogin: String + channels: [Channel] + directMessages: [Channel] +} diff --git a/packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.graphql b/packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.graphql new file mode 100644 index 000000000000..a360cc2a72b9 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.graphql @@ -0,0 +1,7 @@ +enum UserStatus { + ONLINE + AWAY + BUSY + INVISIBLE + OFFLINE +} diff --git a/packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.js b/packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.js deleted file mode 100644 index 5e821bb5ee2a..000000000000 --- a/packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.js +++ /dev/null @@ -1,9 +0,0 @@ -export const schema = ` - enum UserStatus { - ONLINE - AWAY - BUSY - INVISIBLE - OFFLINE - } -`; diff --git a/packages/rocketchat-graphql/server/schemas/users/setStatus.graphql b/packages/rocketchat-graphql/server/schemas/users/setStatus.graphql new file mode 100644 index 000000000000..7beb3512a91b --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/users/setStatus.graphql @@ -0,0 +1,3 @@ +type Mutation { + setStatus(status: UserStatus!): User +} From dfe8d1448a51193795949dde0a3bbca16dee1535 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Sat, 2 Sep 2017 12:26:44 +0200 Subject: [PATCH 24/42] WIP - LAST ONE --- .../.npm/package/npm-shrinkwrap.json | 4 +- packages/rocketchat-accounts/README.md | 3 + packages/rocketchat-accounts/server/config.js | 1 - packages/rocketchat-accounts/server/index.js | 1 - .../rocketchat-grant/server/authenticate.js | 1 + packages/rocketchat-grant/server/grant.js | 2 + .../.npm/package/npm-shrinkwrap.json | 215 +++++++++--------- packages/rocketchat-graphql/package.js | 3 +- packages/rocketchat-graphql/server/api.js | 10 +- .../server/helpers/authenticated.js | 1 - .../server/helpers/property.js | 3 - .../resolvers/accounts/OauthProvider-type.js | 2 +- .../server/resolvers/accounts/index.js | 2 +- .../resolvers/accounts/oauthProviders.js | 2 +- .../server/resolvers/channels/Channel-type.js | 6 +- .../resolvers/channels/ChannelFilter-input.js | 2 +- .../channels/ChannelNameAndDirect-input.js | 2 +- .../resolvers/channels/ChannelSort-enum.js | 2 +- .../server/resolvers/channels/Privacy-enum.js | 2 +- .../resolvers/channels/channelByName.js | 4 +- .../server/resolvers/channels/channels.js | 4 +- .../resolvers/channels/channelsByUser.js | 4 +- .../resolvers/channels/createChannel.js | 4 +- .../resolvers/channels/directChannel.js | 4 +- .../server/resolvers/channels/hideChannel.js | 3 +- .../server/resolvers/channels/leaveChannel.js | 3 +- .../server/resolvers/messages/Message-type.js | 6 +- .../messages/MessageIdentifier-input.js | 2 +- .../messages/MessagesWithCursor-type.js | 2 +- .../resolvers/messages/Reaction-type.js | 2 +- .../messages/addReactionToMessage.js | 3 +- .../resolvers/messages/chatMessageAdded.js | 32 ++- .../resolvers/messages/deleteMessage.js | 3 +- .../server/resolvers/messages/editMessage.js | 3 +- .../server/resolvers/messages/messages.js | 22 +- .../server/resolvers/messages/sendMessage.js | 14 +- .../server/resolvers/users/User-type.js | 6 +- .../server/resolvers/users/UserStatus-enum.js | 2 +- .../server/resolvers/users/setStatus.js | 4 +- ...type.graphql => LoginResult-type.graphqls} | 0 ...pe.graphql => OauthProvider-type.graphqls} | 0 ...viders.graphql => oauthProviders.graphqls} | 0 ...nel-type.graphql => Channel-type.graphqls} | 0 ...t.graphql => ChannelFilter-input.graphqls} | 0 ...ql => ChannelNameAndDirect-input.graphqls} | 0 ...enum.graphql => ChannelSort-enum.graphqls} | 0 ...acy-enum.graphql => Privacy-enum.graphqls} | 0 ...lByName.graphql => channelByName.graphqls} | 0 .../{channels.graphql => channels.graphqls} | 0 ...ByUser.graphql => channelsByUser.graphqls} | 0 ...Channel.graphql => createChannel.graphqls} | 0 ...Channel.graphql => directChannel.graphqls} | 0 ...deChannel.graphql => hideChannel.graphqls} | 0 ...eChannel.graphql => leaveChannel.graphqls} | 0 ...age-type.graphql => Message-type.graphqls} | 0 ...aphql => MessageIdentifier-input.graphqls} | 0 ...aphql => MessagesWithCursor-type.graphqls} | 0 ...on-type.graphql => Reaction-type.graphqls} | 0 ....graphql => addReactionToMessage.graphqls} | 0 .../schemas/messages/chatMessageAdded.graphql | 3 - .../messages/chatMessageAdded.graphqls | 3 + ...Message.graphql => deleteMessage.graphqls} | 0 ...itMessage.graphql => editMessage.graphqls} | 0 .../{messages.graphql => messages.graphqls} | 2 +- .../schemas/messages/sendMessage.graphql | 3 - .../schemas/messages/sendMessage.graphqls | 3 + .../{User-type.graphql => User-type.graphqls} | 0 ...-enum.graphql => UserStatus-enum.graphqls} | 0 .../{setStatus.graphql => setStatus.graphqls} | 0 69 files changed, 232 insertions(+), 173 deletions(-) create mode 100644 packages/rocketchat-accounts/README.md delete mode 100644 packages/rocketchat-graphql/server/helpers/property.js rename packages/rocketchat-graphql/server/schemas/accounts/{LoginResult-type.graphql => LoginResult-type.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/accounts/{OauthProvider-type.graphql => OauthProvider-type.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/accounts/{oauthProviders.graphql => oauthProviders.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{Channel-type.graphql => Channel-type.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{ChannelFilter-input.graphql => ChannelFilter-input.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{ChannelNameAndDirect-input.graphql => ChannelNameAndDirect-input.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{ChannelSort-enum.graphql => ChannelSort-enum.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{Privacy-enum.graphql => Privacy-enum.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{channelByName.graphql => channelByName.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{channels.graphql => channels.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{channelsByUser.graphql => channelsByUser.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{createChannel.graphql => createChannel.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{directChannel.graphql => directChannel.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{hideChannel.graphql => hideChannel.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/channels/{leaveChannel.graphql => leaveChannel.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/messages/{Message-type.graphql => Message-type.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/messages/{MessageIdentifier-input.graphql => MessageIdentifier-input.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/messages/{MessagesWithCursor-type.graphql => MessagesWithCursor-type.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/messages/{Reaction-type.graphql => Reaction-type.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/messages/{addReactionToMessage.graphql => addReactionToMessage.graphqls} (100%) delete mode 100644 packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphqls rename packages/rocketchat-graphql/server/schemas/messages/{deleteMessage.graphql => deleteMessage.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/messages/{editMessage.graphql => editMessage.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/messages/{messages.graphql => messages.graphqls} (81%) delete mode 100644 packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphql create mode 100644 packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphqls rename packages/rocketchat-graphql/server/schemas/users/{User-type.graphql => User-type.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/users/{UserStatus-enum.graphql => UserStatus-enum.graphqls} (100%) rename packages/rocketchat-graphql/server/schemas/users/{setStatus.graphql => setStatus.graphqls} (100%) diff --git a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json index 720452518c3b..9bee17427949 100644 --- a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json @@ -53,8 +53,8 @@ "from": "bufferjs@1.1.0" }, "core-js": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.0.tgz", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.1.tgz", "from": "core-js@>=2.5.0 <3.0.0" }, "core-util-is": { diff --git a/packages/rocketchat-accounts/README.md b/packages/rocketchat-accounts/README.md new file mode 100644 index 000000000000..91ee3cc93aa5 --- /dev/null +++ b/packages/rocketchat-accounts/README.md @@ -0,0 +1,3 @@ +# rocketchat:accounts + +Integration with `js-accounts` system. diff --git a/packages/rocketchat-accounts/server/config.js b/packages/rocketchat-accounts/server/config.js index 621db418d784..21a6629b0b08 100644 --- a/packages/rocketchat-accounts/server/config.js +++ b/packages/rocketchat-accounts/server/config.js @@ -7,7 +7,6 @@ Meteor.startup(() => { const mongodb = MongoInternals.defaultRemoteCollectionDriver().mongo.db; const mongoAdapter = new MongoAdapter(mongodb, { - // XXX: UserId in RocketChat is a string(17) value convertUserIdToMongoObjectId: false }); diff --git a/packages/rocketchat-accounts/server/index.js b/packages/rocketchat-accounts/server/index.js index 88ebb9b52977..7651774b4e8c 100644 --- a/packages/rocketchat-accounts/server/index.js +++ b/packages/rocketchat-accounts/server/index.js @@ -1,4 +1,3 @@ -// import './fix'; import './config'; import AccountsServer from '@accounts/server'; diff --git a/packages/rocketchat-grant/server/authenticate.js b/packages/rocketchat-grant/server/authenticate.js index ad68fb009681..7e5aae261e1f 100644 --- a/packages/rocketchat-grant/server/authenticate.js +++ b/packages/rocketchat-grant/server/authenticate.js @@ -1,4 +1,5 @@ import { AccountsServer } from 'meteor/rocketchat:accounts'; +import { RocketChat } from 'meteor/rocketchat:lib'; import { Accounts } from 'meteor/accounts-base'; import { Meteor } from 'meteor/meteor'; diff --git a/packages/rocketchat-grant/server/grant.js b/packages/rocketchat-grant/server/grant.js index 0f8890652909..b4adfd3081dd 100644 --- a/packages/rocketchat-grant/server/grant.js +++ b/packages/rocketchat-grant/server/grant.js @@ -1,3 +1,5 @@ +import { RocketChat } from 'meteor/rocketchat:lib'; + import Providers from './providers'; import Settings from './settings'; import { path, generateCallback, generateAppCallback } from './routes'; diff --git a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json index 6a2374ea66c7..10d14533cd41 100644 --- a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json @@ -3,510 +3,505 @@ "accepts": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.4.tgz", - "from": "accepts@https://registry.npmjs.org/accepts/-/accepts-1.3.4.tgz" + "from": "accepts@>=1.3.3 <1.4.0" }, "apollo-server-core": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/apollo-server-core/-/apollo-server-core-1.1.0.tgz", - "from": "apollo-server-core@https://registry.npmjs.org/apollo-server-core/-/apollo-server-core-1.1.0.tgz" + "from": "apollo-server-core@>=1.1.0 <2.0.0" }, "apollo-server-express": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/apollo-server-express/-/apollo-server-express-1.1.2.tgz", - "from": "apollo-server-express@https://registry.npmjs.org/apollo-server-express/-/apollo-server-express-1.1.2.tgz" + "from": "apollo-server-express@1.1.2" }, "apollo-server-module-graphiql": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/apollo-server-module-graphiql/-/apollo-server-module-graphiql-1.1.2.tgz", - "from": "apollo-server-module-graphiql@https://registry.npmjs.org/apollo-server-module-graphiql/-/apollo-server-module-graphiql-1.1.2.tgz" + "from": "apollo-server-module-graphiql@>=1.1.2 <2.0.0" }, "apollo-tracing": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/apollo-tracing/-/apollo-tracing-0.0.7.tgz", - "from": "apollo-tracing@https://registry.npmjs.org/apollo-tracing/-/apollo-tracing-0.0.7.tgz" + "from": "apollo-tracing@>=0.0.7 <0.0.8" }, "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "from": "array-flatten@https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz" + "from": "array-flatten@1.1.1" }, "babel-polyfill": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", - "from": "babel-polyfill@https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", + "from": "babel-polyfill@>=6.23.0 <7.0.0", "dependencies": { "regenerator-runtime": { "version": "0.10.5", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", - "from": "regenerator-runtime@https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz" + "from": "regenerator-runtime@>=0.10.5 <0.11.0" } } }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", - "from": "babel-runtime@https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz" + "from": "babel-runtime@>=6.23.0 <7.0.0" }, "backo2": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", - "from": "backo2@https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz" + "from": "backo2@>=1.0.2 <2.0.0" }, "base64url": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz", - "from": "base64url@https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz" + "from": "base64url@>=2.0.0 <3.0.0" }, "bcryptjs": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz", - "from": "bcryptjs@https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz" + "from": "bcryptjs@>=2.4.0 <3.0.0" }, "body-parser": { "version": "1.17.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.17.2.tgz", - "from": "body-parser@https://registry.npmjs.org/body-parser/-/body-parser-1.17.2.tgz" + "from": "body-parser@1.17.2" }, "buffer-equal-constant-time": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", - "from": "buffer-equal-constant-time@https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz" + "from": "buffer-equal-constant-time@1.0.1" }, "bytes": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz", - "from": "bytes@https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz" + "from": "bytes@2.4.0" }, "content-disposition": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", - "from": "content-disposition@https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz" + "from": "content-disposition@0.5.2" }, "content-type": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.2.tgz", - "from": "content-type@https://registry.npmjs.org/content-type/-/content-type-1.0.2.tgz" + "from": "content-type@>=1.0.2 <1.1.0" }, "cookie": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", - "from": "cookie@https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz" + "from": "cookie@0.3.1" }, "cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", - "from": "cookie-signature@https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz" + "from": "cookie-signature@1.0.6" }, "core-js": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.0.tgz", - "from": "core-js@https://registry.npmjs.org/core-js/-/core-js-2.5.0.tgz" + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.1.tgz", + "from": "core-js@>=2.4.0 <3.0.0" }, "cors": { "version": "2.8.4", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.4.tgz", - "from": "cors@https://registry.npmjs.org/cors/-/cors-2.8.4.tgz" + "from": "cors@2.8.4" }, "crypto": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/crypto/-/crypto-0.0.3.tgz", - "from": "crypto@https://registry.npmjs.org/crypto/-/crypto-0.0.3.tgz" + "from": "crypto@>=0.0.3 <0.0.4" }, "debug": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.7.tgz", - "from": "debug@https://registry.npmjs.org/debug/-/debug-2.6.7.tgz" + "from": "debug@2.6.7" }, "deepmerge": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-1.5.1.tgz", - "from": "deepmerge@https://registry.npmjs.org/deepmerge/-/deepmerge-1.5.1.tgz" + "from": "deepmerge@>=1.3.2 <2.0.0" }, "depd": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", - "from": "depd@https://registry.npmjs.org/depd/-/depd-1.1.1.tgz" + "from": "depd@>=1.1.0 <1.2.0" }, "deprecated-decorator": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz", - "from": "deprecated-decorator@https://registry.npmjs.org/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz" + "from": "deprecated-decorator@>=0.1.6 <0.2.0" }, "destroy": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "from": "destroy@https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz" + "from": "destroy@>=1.0.4 <1.1.0" }, "ecdsa-sig-formatter": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz", - "from": "ecdsa-sig-formatter@https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz" + "from": "ecdsa-sig-formatter@1.0.9" }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "from": "ee-first@https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz" + "from": "ee-first@1.1.1" }, "encodeurl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz", - "from": "encodeurl@https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz" + "from": "encodeurl@>=1.0.1 <1.1.0" }, "es6-promise": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.1.1.tgz", - "from": "es6-promise@https://registry.npmjs.org/es6-promise/-/es6-promise-4.1.1.tgz" + "from": "es6-promise@>=4.0.5 <5.0.0" }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "from": "escape-html@https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz" + "from": "escape-html@>=1.0.3 <1.1.0" }, "etag": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.0.tgz", - "from": "etag@https://registry.npmjs.org/etag/-/etag-1.8.0.tgz" + "from": "etag@>=1.8.0 <1.9.0" }, "eventemitter3": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz", - "from": "eventemitter3@https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz" + "from": "eventemitter3@>=2.0.3 <3.0.0" }, "express": { "version": "4.15.4", "resolved": "https://registry.npmjs.org/express/-/express-4.15.4.tgz", - "from": "express@https://registry.npmjs.org/express/-/express-4.15.4.tgz", + "from": "express@4.15.4", "dependencies": { "debug": { "version": "2.6.8", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "from": "debug@https://registry.npmjs.org/debug/-/debug-2.6.8.tgz" + "from": "debug@2.6.8" }, "qs": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.0.tgz", - "from": "qs@https://registry.npmjs.org/qs/-/qs-6.5.0.tgz" + "from": "qs@6.5.0" } } }, "finalhandler": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.4.tgz", - "from": "finalhandler@https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.4.tgz", + "from": "finalhandler@>=1.0.4 <1.1.0", "dependencies": { "debug": { "version": "2.6.8", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "from": "debug@https://registry.npmjs.org/debug/-/debug-2.6.8.tgz" + "from": "debug@2.6.8" } } }, "forwarded": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.0.tgz", - "from": "forwarded@https://registry.npmjs.org/forwarded/-/forwarded-0.1.0.tgz" + "from": "forwarded@>=0.1.0 <0.2.0" }, "fresh": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.0.tgz", - "from": "fresh@https://registry.npmjs.org/fresh/-/fresh-0.5.0.tgz" + "from": "fresh@0.5.0" }, "graphql": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/graphql/-/graphql-0.10.3.tgz", - "from": "graphql@https://registry.npmjs.org/graphql/-/graphql-0.10.3.tgz" + "from": "graphql@0.10.3" }, "graphql-subscriptions": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-0.4.4.tgz", - "from": "graphql-subscriptions@https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-0.4.4.tgz" + "from": "graphql-subscriptions@0.4.4" }, "graphql-tag": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.4.2.tgz", - "from": "graphql-tag@https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.4.2.tgz" + "from": "graphql-tag@>=2.4.2 <3.0.0" }, "graphql-tools": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-1.2.2.tgz", - "from": "graphql-tools@https://registry.npmjs.org/graphql-tools/-/graphql-tools-1.2.2.tgz" + "from": "graphql-tools@1.2.2" }, "hoek": { "version": "2.16.3", "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", - "from": "hoek@https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz" + "from": "hoek@>=2.0.0 <3.0.0" }, "http-errors": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", - "from": "http-errors@https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz" + "from": "http-errors@>=1.6.1 <1.7.0" }, "iconv-lite": { "version": "0.4.15", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.15.tgz", - "from": "iconv-lite@https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.15.tgz" + "from": "iconv-lite@0.4.15" }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "from": "inherits@https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz" + "from": "inherits@2.0.3" }, "ipaddr.js": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.4.0.tgz", - "from": "ipaddr.js@https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.4.0.tgz" + "from": "ipaddr.js@1.4.0" }, "isemail": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/isemail/-/isemail-1.2.0.tgz", - "from": "isemail@https://registry.npmjs.org/isemail/-/isemail-1.2.0.tgz" + "from": "isemail@>=1.0.0 <2.0.0" }, "iterall": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.1.1.tgz", - "from": "iterall@https://registry.npmjs.org/iterall/-/iterall-1.1.1.tgz" + "from": "iterall@>=1.1.0 <2.0.0" }, "joi": { "version": "6.10.1", "resolved": "https://registry.npmjs.org/joi/-/joi-6.10.1.tgz", - "from": "joi@https://registry.npmjs.org/joi/-/joi-6.10.1.tgz" + "from": "joi@>=6.10.1 <7.0.0" }, "jsonwebtoken": { "version": "7.4.3", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.3.tgz", - "from": "jsonwebtoken@https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.3.tgz" + "from": "jsonwebtoken@>=7.2.1 <8.0.0" }, "jwa": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz", - "from": "jwa@https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz" + "from": "jwa@>=1.1.4 <2.0.0" }, "jws": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/jws/-/jws-3.1.4.tgz", - "from": "jws@https://registry.npmjs.org/jws/-/jws-3.1.4.tgz" + "from": "jws@>=3.1.4 <4.0.0" }, "jwt-decode": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz", - "from": "jwt-decode@https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz" - }, - "kamilkisiela-graphql-api": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/kamilkisiela-graphql-api/-/kamilkisiela-graphql-api-0.1.1.tgz", - "from": "kamilkisiela-graphql-api@https://registry.npmjs.org/kamilkisiela-graphql-api/-/kamilkisiela-graphql-api-0.1.1.tgz" + "from": "jwt-decode@>=2.1.0 <3.0.0" }, "kamilkisiela-merge-graphql-schemas": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/kamilkisiela-merge-graphql-schemas/-/kamilkisiela-merge-graphql-schemas-1.1.2.tgz", - "from": "kamilkisiela-merge-graphql-schemas@https://registry.npmjs.org/kamilkisiela-merge-graphql-schemas/-/kamilkisiela-merge-graphql-schemas-1.1.2.tgz" + "from": "kamilkisiela-merge-graphql-schemas@1.1.2" }, "lodash": { "version": "4.17.4", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", - "from": "lodash@https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz" + "from": "lodash@>=4.16.4 <5.0.0" }, "lodash.assign": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz", - "from": "lodash.assign@https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz" + "from": "lodash.assign@>=4.2.0 <5.0.0" }, "lodash.isobject": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/lodash.isobject/-/lodash.isobject-3.0.2.tgz", - "from": "lodash.isobject@https://registry.npmjs.org/lodash.isobject/-/lodash.isobject-3.0.2.tgz" + "from": "lodash.isobject@>=3.0.2 <4.0.0" }, "lodash.isstring": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", - "from": "lodash.isstring@https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz" + "from": "lodash.isstring@>=4.0.1 <5.0.0" }, "lodash.once": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", - "from": "lodash.once@https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz" + "from": "lodash.once@>=4.0.0 <5.0.0" + }, + "lodash.property": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.property/-/lodash.property-4.4.2.tgz", + "from": "lodash.property@4.4.2" }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "from": "media-typer@https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz" + "from": "media-typer@0.3.0" }, "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "from": "merge-descriptors@https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz" - }, - "meteor-promise": { - "version": "0.8.6", - "resolved": "https://registry.npmjs.org/meteor-promise/-/meteor-promise-0.8.6.tgz", - "from": "meteor-promise@https://registry.npmjs.org/meteor-promise/-/meteor-promise-0.8.6.tgz" + "from": "merge-descriptors@1.0.1" }, "methods": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "from": "methods@https://registry.npmjs.org/methods/-/methods-1.1.2.tgz" + "from": "methods@>=1.1.2 <1.2.0" }, "mime": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz", - "from": "mime@https://registry.npmjs.org/mime/-/mime-1.3.4.tgz" + "from": "mime@1.3.4" }, "mime-db": { "version": "1.29.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.29.0.tgz", - "from": "mime-db@https://registry.npmjs.org/mime-db/-/mime-db-1.29.0.tgz" + "from": "mime-db@>=1.29.0 <1.30.0" }, "mime-types": { "version": "2.1.16", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.16.tgz", - "from": "mime-types@https://registry.npmjs.org/mime-types/-/mime-types-2.1.16.tgz" + "from": "mime-types@>=2.1.15 <2.2.0" }, "moment": { "version": "2.18.1", "resolved": "https://registry.npmjs.org/moment/-/moment-2.18.1.tgz", - "from": "moment@https://registry.npmjs.org/moment/-/moment-2.18.1.tgz" + "from": "moment@>=2.0.0 <3.0.0" }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "from": "ms@https://registry.npmjs.org/ms/-/ms-2.0.0.tgz" + "from": "ms@>=2.0.0 <3.0.0" }, "negotiator": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", - "from": "negotiator@https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz" + "from": "negotiator@0.6.1" }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "from": "object-assign@https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz" + "from": "object-assign@>=4.0.0 <5.0.0" }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "from": "on-finished@https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz" + "from": "on-finished@>=2.3.0 <2.4.0" }, "parseurl": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.1.tgz", - "from": "parseurl@https://registry.npmjs.org/parseurl/-/parseurl-1.3.1.tgz" + "from": "parseurl@>=1.3.1 <1.4.0" }, "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "from": "path-to-regexp@https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz" + "from": "path-to-regexp@0.1.7" }, "proxy-addr": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.5.tgz", - "from": "proxy-addr@https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.5.tgz" + "from": "proxy-addr@>=1.1.5 <1.2.0" }, "qs": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz", - "from": "qs@https://registry.npmjs.org/qs/-/qs-6.4.0.tgz" + "from": "qs@6.4.0" }, "range-parser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", - "from": "range-parser@https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz" + "from": "range-parser@>=1.2.0 <1.3.0" }, "raw-body": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.2.0.tgz", - "from": "raw-body@https://registry.npmjs.org/raw-body/-/raw-body-2.2.0.tgz" + "from": "raw-body@>=2.2.0 <2.3.0" }, "regenerator-runtime": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz", - "from": "regenerator-runtime@https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz" + "from": "regenerator-runtime@>=0.11.0 <0.12.0" }, "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "from": "safe-buffer@https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz" + "from": "safe-buffer@>=5.0.1 <6.0.0" }, "send": { "version": "0.15.4", "resolved": "https://registry.npmjs.org/send/-/send-0.15.4.tgz", - "from": "send@https://registry.npmjs.org/send/-/send-0.15.4.tgz", + "from": "send@0.15.4", "dependencies": { "debug": { "version": "2.6.8", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "from": "debug@https://registry.npmjs.org/debug/-/debug-2.6.8.tgz" + "from": "debug@2.6.8" } } }, "serve-static": { "version": "1.12.4", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.12.4.tgz", - "from": "serve-static@https://registry.npmjs.org/serve-static/-/serve-static-1.12.4.tgz" + "from": "serve-static@1.12.4" }, "setprototypeof": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", - "from": "setprototypeof@https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz" + "from": "setprototypeof@1.0.3" }, "statuses": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", - "from": "statuses@https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz" + "from": "statuses@>=1.3.1 <2.0.0" }, "subscriptions-transport-ws": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/subscriptions-transport-ws/-/subscriptions-transport-ws-0.8.2.tgz", - "from": "subscriptions-transport-ws@https://registry.npmjs.org/subscriptions-transport-ws/-/subscriptions-transport-ws-0.8.2.tgz" + "from": "subscriptions-transport-ws@0.8.2" }, "symbol-observable": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.4.tgz", - "from": "symbol-observable@https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.4.tgz" + "from": "symbol-observable@>=1.0.4 <2.0.0" }, "topo": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/topo/-/topo-1.1.0.tgz", - "from": "topo@https://registry.npmjs.org/topo/-/topo-1.1.0.tgz" + "from": "topo@>=1.0.0 <2.0.0" }, "type-is": { "version": "1.6.15", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", - "from": "type-is@https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz" + "from": "type-is@>=1.6.15 <1.7.0" }, "ultron": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.0.tgz", - "from": "ultron@https://registry.npmjs.org/ultron/-/ultron-1.1.0.tgz" + "from": "ultron@>=1.1.0 <1.2.0" }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "from": "unpipe@https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz" + "from": "unpipe@1.0.0" }, "utils-merge": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz", - "from": "utils-merge@https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz" + "from": "utils-merge@1.0.0" }, "uuid": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", - "from": "uuid@https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz" + "from": "uuid@>=3.0.1 <4.0.0" }, "vary": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.1.tgz", - "from": "vary@https://registry.npmjs.org/vary/-/vary-1.1.1.tgz" + "from": "vary@>=1.0.0 <2.0.0" }, "ws": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/ws/-/ws-3.1.0.tgz", - "from": "ws@https://registry.npmjs.org/ws/-/ws-3.1.0.tgz" + "from": "ws@>=3.0.0 <4.0.0" }, "xtend": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "from": "xtend@https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz" + "from": "xtend@>=4.0.1 <5.0.0" } } } diff --git a/packages/rocketchat-graphql/package.js b/packages/rocketchat-graphql/package.js index def84c4c84c9..8d6ff940e0c1 100644 --- a/packages/rocketchat-graphql/package.js +++ b/packages/rocketchat-graphql/package.js @@ -20,7 +20,7 @@ Package.onUse(function(api) { }); Npm.depends({ - 'kamilkisiela-graphql-api': '0.1.1', + '@accounts/graphql-api': '0.1.1', 'apollo-server-express': '1.1.2', 'cors': '2.8.4', 'body-parser': '1.17.2', @@ -28,6 +28,7 @@ Npm.depends({ 'graphql': '0.10.3', 'graphql-subscriptions': '0.4.4', 'graphql-tools': '1.2.2', + 'lodash.property': '4.4.2', 'kamilkisiela-merge-graphql-schemas': '1.1.2', 'subscriptions-transport-ws': '0.8.2' }); diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index 9c1f36c00a90..494429f52e97 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -1,5 +1,5 @@ import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'; -import { JSAccountsContext as jsAccountsContext } from 'kamilkisiela-graphql-api'; +import { JSAccountsContext as jsAccountsContext } from '@accounts/graphql-api'; import { SubscriptionServer } from 'subscriptions-transport-ws'; import { execute, subscribe } from 'graphql'; import { Meteor } from 'meteor/meteor'; @@ -41,7 +41,13 @@ graphQLServer.use('/graphiql', graphiqlExpress({ new SubscriptionServer({ schema: executableSchema, execute, - subscribe + subscribe, + onOperation: ({context}) => { + console.log('context', context); + return { + authToken: context.Authorization + }; + } }, { path: '/subscriptions', diff --git a/packages/rocketchat-graphql/server/helpers/authenticated.js b/packages/rocketchat-graphql/server/helpers/authenticated.js index c36223b94b5a..44c54e053996 100644 --- a/packages/rocketchat-graphql/server/helpers/authenticated.js +++ b/packages/rocketchat-graphql/server/helpers/authenticated.js @@ -1,6 +1,5 @@ import { AccountsServer } from 'meteor/rocketchat:accounts'; //import { authenticated as _authenticated } from '@accounts/graphql-api'; -// import { authenticated as _authenticated } from 'kamilkisiela-graphql-api'; import { authenticated as _authenticated } from '../mocks/accounts/graphql-api'; export const authenticated = (resolver) => { diff --git a/packages/rocketchat-graphql/server/helpers/property.js b/packages/rocketchat-graphql/server/helpers/property.js deleted file mode 100644 index 65485cae9868..000000000000 --- a/packages/rocketchat-graphql/server/helpers/property.js +++ /dev/null @@ -1,3 +0,0 @@ -export function property(key) { - return (object) => object == null ? undefined : object[key]; -} diff --git a/packages/rocketchat-graphql/server/resolvers/accounts/OauthProvider-type.js b/packages/rocketchat-graphql/server/resolvers/accounts/OauthProvider-type.js index fd13e7f61106..7cf39ff56139 100644 --- a/packages/rocketchat-graphql/server/resolvers/accounts/OauthProvider-type.js +++ b/packages/rocketchat-graphql/server/resolvers/accounts/OauthProvider-type.js @@ -1,4 +1,4 @@ -import schema from '../../schemas/accounts/OauthProvider-type.graphql'; +import schema from '../../schemas/accounts/OauthProvider-type.graphqls'; export { schema diff --git a/packages/rocketchat-graphql/server/resolvers/accounts/index.js b/packages/rocketchat-graphql/server/resolvers/accounts/index.js index 57d98cce5962..02aceb574911 100644 --- a/packages/rocketchat-graphql/server/resolvers/accounts/index.js +++ b/packages/rocketchat-graphql/server/resolvers/accounts/index.js @@ -1,4 +1,4 @@ -import { createJSAccountsGraphQL } from 'kamilkisiela-graphql-api'; +import { createJSAccountsGraphQL } from '@accounts/graphql-api'; import { AccountsServer } from 'meteor/rocketchat:accounts'; import { mergeTypes, mergeResolvers } from 'kamilkisiela-merge-graphql-schemas'; diff --git a/packages/rocketchat-graphql/server/resolvers/accounts/oauthProviders.js b/packages/rocketchat-graphql/server/resolvers/accounts/oauthProviders.js index 0cccbc9381d9..de487b8f9265 100644 --- a/packages/rocketchat-graphql/server/resolvers/accounts/oauthProviders.js +++ b/packages/rocketchat-graphql/server/resolvers/accounts/oauthProviders.js @@ -1,7 +1,7 @@ import { HTTP } from 'meteor/http'; import { Meteor } from 'meteor/meteor'; -import schema from '../../schemas/accounts/oauthProviders.graphql'; +import schema from '../../schemas/accounts/oauthProviders.graphqls'; function isJSON(obj) { try { diff --git a/packages/rocketchat-graphql/server/resolvers/channels/Channel-type.js b/packages/rocketchat-graphql/server/resolvers/channels/Channel-type.js index e4dfb9ba4371..e16dffa8ab83 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/Channel-type.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/Channel-type.js @@ -1,5 +1,7 @@ -import { property } from '../../helpers/property'; -import schema from '../../schemas/channels/Channel-type.graphql'; +import { RocketChat } from 'meteor/rocketchat:lib'; +import property from 'lodash.property'; + +import schema from '../../schemas/channels/Channel-type.graphqls'; const resolver = { Channel: { diff --git a/packages/rocketchat-graphql/server/resolvers/channels/ChannelFilter-input.js b/packages/rocketchat-graphql/server/resolvers/channels/ChannelFilter-input.js index 54c5be23b0ff..cb1c26b0efa5 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/ChannelFilter-input.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/ChannelFilter-input.js @@ -1,4 +1,4 @@ -import schema from '../../schemas/channels/ChannelFilter-input.graphql'; +import schema from '../../schemas/channels/ChannelFilter-input.graphqls'; export { schema diff --git a/packages/rocketchat-graphql/server/resolvers/channels/ChannelNameAndDirect-input.js b/packages/rocketchat-graphql/server/resolvers/channels/ChannelNameAndDirect-input.js index ad769ae36913..70cb2f18e6b6 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/ChannelNameAndDirect-input.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/ChannelNameAndDirect-input.js @@ -1,4 +1,4 @@ -import schema from '../../schemas/channels/ChannelNameAndDirect-input.graphql'; +import schema from '../../schemas/channels/ChannelNameAndDirect-input.graphqls'; export { schema diff --git a/packages/rocketchat-graphql/server/resolvers/channels/ChannelSort-enum.js b/packages/rocketchat-graphql/server/resolvers/channels/ChannelSort-enum.js index 3cd8b5f7b8d3..39e2cfc9aef5 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/ChannelSort-enum.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/ChannelSort-enum.js @@ -1,4 +1,4 @@ -import schema from '../../schemas/channels/ChannelSort-enum.graphql'; +import schema from '../../schemas/channels/ChannelSort-enum.graphqls'; export { schema diff --git a/packages/rocketchat-graphql/server/resolvers/channels/Privacy-enum.js b/packages/rocketchat-graphql/server/resolvers/channels/Privacy-enum.js index bc0172b74adb..978a69b5ac0f 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/Privacy-enum.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/Privacy-enum.js @@ -1,4 +1,4 @@ -import schema from '../../schemas/channels/Privacy-enum.graphql'; +import schema from '../../schemas/channels/Privacy-enum.graphqls'; export { schema diff --git a/packages/rocketchat-graphql/server/resolvers/channels/channelByName.js b/packages/rocketchat-graphql/server/resolvers/channels/channelByName.js index 060e2a2526a6..580280b549a2 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/channelByName.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/channelByName.js @@ -1,6 +1,8 @@ +import { RocketChat } from 'meteor/rocketchat:lib'; + import { authenticated } from '../../helpers/authenticated'; import { roomPublicFields } from './settings'; -import schema from '../../schemas/channels/channelByName.graphql'; +import schema from '../../schemas/channels/channelByName.graphqls'; const resolver = { Query: { diff --git a/packages/rocketchat-graphql/server/resolvers/channels/channels.js b/packages/rocketchat-graphql/server/resolvers/channels/channels.js index 6087771b86fd..04723ff5f5d4 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/channels.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/channels.js @@ -1,6 +1,8 @@ +import { RocketChat } from 'meteor/rocketchat:lib'; + import { authenticated } from '../../helpers/authenticated'; import { roomPublicFields } from './settings'; -import schema from '../../schemas/channels/channels.graphql'; +import schema from '../../schemas/channels/channels.graphqls'; const resolver = { Query: { diff --git a/packages/rocketchat-graphql/server/resolvers/channels/channelsByUser.js b/packages/rocketchat-graphql/server/resolvers/channels/channelsByUser.js index 29a240e5c000..4fdc6e15a309 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/channelsByUser.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/channelsByUser.js @@ -1,6 +1,8 @@ +import { RocketChat } from 'meteor/rocketchat:lib'; + import { authenticated } from '../../helpers/authenticated'; import { roomPublicFields } from './settings'; -import schema from '../../schemas/channels/channelsByUser.graphql'; +import schema from '../../schemas/channels/channelsByUser.graphqls'; const resolver = { Query: { diff --git a/packages/rocketchat-graphql/server/resolvers/channels/createChannel.js b/packages/rocketchat-graphql/server/resolvers/channels/createChannel.js index e0f8a84d6a3d..59435add38bb 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/createChannel.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/createChannel.js @@ -1,5 +1,7 @@ +import { RocketChat } from 'meteor/rocketchat:lib'; + import { authenticated } from '../../helpers/authenticated'; -import schema from '../../schemas/channels/createChannel.graphql'; +import schema from '../../schemas/channels/createChannel.graphqls'; const resolver = { Mutation: { diff --git a/packages/rocketchat-graphql/server/resolvers/channels/directChannel.js b/packages/rocketchat-graphql/server/resolvers/channels/directChannel.js index 2218cdf7837b..e18e39af19dc 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/directChannel.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/directChannel.js @@ -1,6 +1,8 @@ +import { RocketChat } from 'meteor/rocketchat:lib'; + import { authenticated } from '../../helpers/authenticated'; import { roomPublicFields } from './settings'; -import schema from '../../schemas/channels/directChannel.graphql'; +import schema from '../../schemas/channels/directChannel.graphqls'; const resolver = { Query: { diff --git a/packages/rocketchat-graphql/server/resolvers/channels/hideChannel.js b/packages/rocketchat-graphql/server/resolvers/channels/hideChannel.js index 23cd1017f985..08c55efa7796 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/hideChannel.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/hideChannel.js @@ -1,7 +1,8 @@ import { Meteor } from 'meteor/meteor'; +import { RocketChat } from 'meteor/rocketchat:lib'; import { authenticated } from '../../helpers/authenticated'; -import schema from '../../schemas/channels/hideChannel.graphql'; +import schema from '../../schemas/channels/hideChannel.graphqls'; const resolver = { Mutation: { diff --git a/packages/rocketchat-graphql/server/resolvers/channels/leaveChannel.js b/packages/rocketchat-graphql/server/resolvers/channels/leaveChannel.js index 306beff5d7a6..46afd2a08940 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/leaveChannel.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/leaveChannel.js @@ -1,7 +1,8 @@ import { Meteor } from 'meteor/meteor'; +import { RocketChat } from 'meteor/rocketchat:lib'; import { authenticated } from '../../helpers/authenticated'; -import schema from '../../schemas/channels/leaveChannel.graphql'; +import schema from '../../schemas/channels/leaveChannel.graphqls'; const resolver = { Mutation: { diff --git a/packages/rocketchat-graphql/server/resolvers/messages/Message-type.js b/packages/rocketchat-graphql/server/resolvers/messages/Message-type.js index 0fc8c6c36bb4..362ce8b50b60 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/Message-type.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/Message-type.js @@ -1,6 +1,8 @@ -import { property } from '../../helpers/property'; +import { RocketChat } from 'meteor/rocketchat:lib'; +import property from 'lodash.property'; + import { dateToFloat } from '../../helpers/dateToFloat'; -import schema from '../../schemas/messages/Message-type.graphql'; +import schema from '../../schemas/messages/Message-type.graphqls'; const resolver = { Message: { diff --git a/packages/rocketchat-graphql/server/resolvers/messages/MessageIdentifier-input.js b/packages/rocketchat-graphql/server/resolvers/messages/MessageIdentifier-input.js index 63f5a8bbb300..bda12ad6ac68 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/MessageIdentifier-input.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/MessageIdentifier-input.js @@ -1,4 +1,4 @@ -import schema from '../../schemas/messages/MessageIdentifier-input.graphql'; +import schema from '../../schemas/messages/MessageIdentifier-input.graphqls'; export { schema diff --git a/packages/rocketchat-graphql/server/resolvers/messages/MessagesWithCursor-type.js b/packages/rocketchat-graphql/server/resolvers/messages/MessagesWithCursor-type.js index e25dfb592f7a..02e630ff4589 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/MessagesWithCursor-type.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/MessagesWithCursor-type.js @@ -1,4 +1,4 @@ -import schema from '../../schemas/messages/MessagesWithCursor-type.graphql'; +import schema from '../../schemas/messages/MessagesWithCursor-type.graphqls'; export { schema diff --git a/packages/rocketchat-graphql/server/resolvers/messages/Reaction-type.js b/packages/rocketchat-graphql/server/resolvers/messages/Reaction-type.js index 81ec44c5b9b8..37a9c7a71ef6 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/Reaction-type.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/Reaction-type.js @@ -1,4 +1,4 @@ -import schema from '../../schemas/messages/Reaction-type.graphql'; +import schema from '../../schemas/messages/Reaction-type.graphqls'; export { schema diff --git a/packages/rocketchat-graphql/server/resolvers/messages/addReactionToMessage.js b/packages/rocketchat-graphql/server/resolvers/messages/addReactionToMessage.js index 1c915d3a4c9a..29a55ded3d95 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/addReactionToMessage.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/addReactionToMessage.js @@ -1,7 +1,8 @@ import { Meteor } from 'meteor/meteor'; +import { RocketChat } from 'meteor/rocketchat:lib'; import { authenticated } from '../../helpers/authenticated'; -import schema from '../../schemas/messages/addReactionToMessage.graphql'; +import schema from '../../schemas/messages/addReactionToMessage.graphqls'; const resolver = { Mutation: { diff --git a/packages/rocketchat-graphql/server/resolvers/messages/chatMessageAdded.js b/packages/rocketchat-graphql/server/resolvers/messages/chatMessageAdded.js index dfbb818e12b2..08cb14bdb274 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/chatMessageAdded.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/chatMessageAdded.js @@ -1,7 +1,9 @@ import { withFilter } from 'graphql-subscriptions'; +import { RocketChat } from 'meteor/rocketchat:lib'; import { pubsub } from '../../subscriptions'; -import schema from '../../schemas/messages/chatMessageAdded.graphql'; +import { authenticated } from '../../helpers/authenticated'; +import schema from '../../schemas/messages/chatMessageAdded.graphqls'; export const CHAT_MESSAGE_SUBSCRIPTION_TOPIC = 'CHAT_MESSAGE_ADDED'; @@ -9,11 +11,35 @@ export function publishMessage(message) { pubsub.publish(CHAT_MESSAGE_SUBSCRIPTION_TOPIC, { chatMessageAdded: message }); } +function shouldPublish(message, { id, directTo }, username) { + if (id) { + return message.rid === id; + } else if (directTo) { + const room = RocketChat.models.Rooms.findOne({ + usernames: { $all: [directTo, username] }, + t: 'd' + }); + + return room && room._id === message.rid; + } + + return false; +} + const resolver = { Subscription: { chatMessageAdded: { - subscribe: withFilter(() => pubsub.asyncIterator(CHAT_MESSAGE_SUBSCRIPTION_TOPIC), (payload, args) => { - return payload.chatMessageAdded.rid === args.channelId; + subscribe: withFilter(() => pubsub.asyncIterator(CHAT_MESSAGE_SUBSCRIPTION_TOPIC), (payload, args, ctx) => { + // FIX: there's no authToken in context + // TODO: check if middleware applies to subscriptions, probably not. + const channel = { + id: args.channelId, + directTo: args.directTo + }; + + console.log('context in sub', ctx); + + return shouldPublish(payload.chatMessageAdded, channel, ctx.user.username); }) } } diff --git a/packages/rocketchat-graphql/server/resolvers/messages/deleteMessage.js b/packages/rocketchat-graphql/server/resolvers/messages/deleteMessage.js index 851767060869..33225c02f282 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/deleteMessage.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/deleteMessage.js @@ -1,7 +1,8 @@ import { Meteor } from 'meteor/meteor'; +import { RocketChat } from 'meteor/rocketchat:lib'; import { authenticated } from '../../helpers/authenticated'; -import schema from '../../schemas/messages/deleteMessage.graphql'; +import schema from '../../schemas/messages/deleteMessage.graphqls'; const resolver = { Mutation: { diff --git a/packages/rocketchat-graphql/server/resolvers/messages/editMessage.js b/packages/rocketchat-graphql/server/resolvers/messages/editMessage.js index 42973929e23a..0fabc8b34db9 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/editMessage.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/editMessage.js @@ -1,7 +1,8 @@ import { Meteor } from 'meteor/meteor'; +import { RocketChat } from 'meteor/rocketchat:lib'; import { authenticated } from '../../helpers/authenticated'; -import schema from '../../schemas/messages/editMessage.graphql'; +import schema from '../../schemas/messages/editMessage.graphqls'; const resolver = { Mutation: { diff --git a/packages/rocketchat-graphql/server/resolvers/messages/messages.js b/packages/rocketchat-graphql/server/resolvers/messages/messages.js index 6ef4b7502591..a163ebefa406 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/messages.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/messages.js @@ -1,9 +1,11 @@ +import { RocketChat } from 'meteor/rocketchat:lib'; + import { authenticated } from '../../helpers/authenticated'; -import schema from '../../schemas/messages/messages.graphql'; +import schema from '../../schemas/messages/messages.graphqls'; const resolver = { Query: { - messages: authenticated((root, args) => { + messages: authenticated((root, args, { user }) => { const messagesQuery = {}; const messagesOptions = { sort: { ts: -1 } @@ -15,20 +17,24 @@ const resolver = { if (args.channelId) { // channelId channelQuery._id = args.channelId; - } else if (args.channelDetails) { - // channelDetails - channelQuery.name = args.channelDetails.name; - channelQuery.t = args.channelDetails.direct === true ? 'd' : { $ne: 'd' }; + } else if (args.directTo) { + // direct message where directTo is a user id + channelQuery.t = 'd'; + channelQuery.usernames = { $all: [args.directTo, user.username] }; + } else if (args.channelName) { + // non-direct channel + channelQuery.t = { $ne: 'd' }; + channelQuery.name = args.channelName; } else { - console.error('messages query must be called with channelId or channelDetails'); + console.error('messages query must be called with channelId or directTo'); return null; } const channel = RocketChat.models.Rooms.findOne(channelQuery); + let messagesArray = []; if (channel) { - // cursor if (isPagination && args.cursor) { const cursorMsg = RocketChat.models.Messages.findOne(args.cursor, { fields: { ts: 1 } }); diff --git a/packages/rocketchat-graphql/server/resolvers/messages/sendMessage.js b/packages/rocketchat-graphql/server/resolvers/messages/sendMessage.js index c0930382578b..7bbd20b71ec0 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/sendMessage.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/sendMessage.js @@ -1,15 +1,17 @@ /* global processWebhookMessage */ import { authenticated } from '../../helpers/authenticated'; -import schema from '../../schemas/messages/sendMessage.graphql'; +import schema from '../../schemas/messages/sendMessage.graphqls'; const resolver = { Mutation: { - sendMessage: authenticated((root, { channelId, content }, { user }) => { - const messageReturn = processWebhookMessage({ - roomId: channelId, - text: content - }, user)[0]; + sendMessage: authenticated((root, { channelId, directTo, content }, { user }) => { + const options = { + text: content, + channel: channelId || directTo + }; + + const messageReturn = processWebhookMessage(options, user)[0]; if (!messageReturn) { throw new Error('Unknown error'); diff --git a/packages/rocketchat-graphql/server/resolvers/users/User-type.js b/packages/rocketchat-graphql/server/resolvers/users/User-type.js index 6eede62b43ef..f2c13fc58bf3 100644 --- a/packages/rocketchat-graphql/server/resolvers/users/User-type.js +++ b/packages/rocketchat-graphql/server/resolvers/users/User-type.js @@ -1,5 +1,7 @@ -import { property } from '../../helpers/property'; -import schema from '../../schemas/users/User-type.graphql'; +import { RocketChat } from 'meteor/rocketchat:lib'; +import property from 'lodash.property'; + +import schema from '../../schemas/users/User-type.graphqls'; const resolver = { User: { diff --git a/packages/rocketchat-graphql/server/resolvers/users/UserStatus-enum.js b/packages/rocketchat-graphql/server/resolvers/users/UserStatus-enum.js index 61c84d39a6e5..d1d526338c1a 100644 --- a/packages/rocketchat-graphql/server/resolvers/users/UserStatus-enum.js +++ b/packages/rocketchat-graphql/server/resolvers/users/UserStatus-enum.js @@ -1,4 +1,4 @@ -import schema from '../../schemas/users/UserStatus-enum.graphql'; +import schema from '../../schemas/users/UserStatus-enum.graphqls'; export { schema diff --git a/packages/rocketchat-graphql/server/resolvers/users/setStatus.js b/packages/rocketchat-graphql/server/resolvers/users/setStatus.js index 6d6f4aca4902..ad6b4ebef6b6 100644 --- a/packages/rocketchat-graphql/server/resolvers/users/setStatus.js +++ b/packages/rocketchat-graphql/server/resolvers/users/setStatus.js @@ -1,5 +1,7 @@ +import { RocketChat } from 'meteor/rocketchat:lib'; + import { authenticated } from '../../helpers/authenticated'; -import schema from '../../schemas/users/setStatus.graphql'; +import schema from '../../schemas/users/setStatus.graphqls'; const resolver = { Mutation: { diff --git a/packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.graphql b/packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.graphql rename to packages/rocketchat-graphql/server/schemas/accounts/LoginResult-type.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.graphql b/packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.graphql rename to packages/rocketchat-graphql/server/schemas/accounts/OauthProvider-type.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.graphql b/packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.graphql rename to packages/rocketchat-graphql/server/schemas/accounts/oauthProviders.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/Channel-type.graphql b/packages/rocketchat-graphql/server/schemas/channels/Channel-type.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/Channel-type.graphql rename to packages/rocketchat-graphql/server/schemas/channels/Channel-type.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.graphql b/packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.graphql rename to packages/rocketchat-graphql/server/schemas/channels/ChannelFilter-input.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.graphql b/packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.graphql rename to packages/rocketchat-graphql/server/schemas/channels/ChannelNameAndDirect-input.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.graphql b/packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.graphql rename to packages/rocketchat-graphql/server/schemas/channels/ChannelSort-enum.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.graphql b/packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.graphql rename to packages/rocketchat-graphql/server/schemas/channels/Privacy-enum.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelByName.graphql b/packages/rocketchat-graphql/server/schemas/channels/channelByName.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/channelByName.graphql rename to packages/rocketchat-graphql/server/schemas/channels/channelByName.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/channels.graphql b/packages/rocketchat-graphql/server/schemas/channels/channels.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/channels.graphql rename to packages/rocketchat-graphql/server/schemas/channels/channels.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.graphql b/packages/rocketchat-graphql/server/schemas/channels/channelsByUser.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/channelsByUser.graphql rename to packages/rocketchat-graphql/server/schemas/channels/channelsByUser.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/createChannel.graphql b/packages/rocketchat-graphql/server/schemas/channels/createChannel.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/createChannel.graphql rename to packages/rocketchat-graphql/server/schemas/channels/createChannel.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/directChannel.graphql b/packages/rocketchat-graphql/server/schemas/channels/directChannel.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/directChannel.graphql rename to packages/rocketchat-graphql/server/schemas/channels/directChannel.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/hideChannel.graphql b/packages/rocketchat-graphql/server/schemas/channels/hideChannel.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/hideChannel.graphql rename to packages/rocketchat-graphql/server/schemas/channels/hideChannel.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.graphql b/packages/rocketchat-graphql/server/schemas/channels/leaveChannel.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/channels/leaveChannel.graphql rename to packages/rocketchat-graphql/server/schemas/channels/leaveChannel.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/messages/Message-type.graphql b/packages/rocketchat-graphql/server/schemas/messages/Message-type.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/messages/Message-type.graphql rename to packages/rocketchat-graphql/server/schemas/messages/Message-type.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.graphql b/packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.graphql rename to packages/rocketchat-graphql/server/schemas/messages/MessageIdentifier-input.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.graphql b/packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.graphql rename to packages/rocketchat-graphql/server/schemas/messages/MessagesWithCursor-type.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/messages/Reaction-type.graphql b/packages/rocketchat-graphql/server/schemas/messages/Reaction-type.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/messages/Reaction-type.graphql rename to packages/rocketchat-graphql/server/schemas/messages/Reaction-type.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphql b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphql rename to packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphql b/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphql deleted file mode 100644 index f88b2979ca5a..000000000000 --- a/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphql +++ /dev/null @@ -1,3 +0,0 @@ -type Subscription { - chatMessageAdded(channelId: String!): Message -} diff --git a/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphqls b/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphqls new file mode 100644 index 000000000000..d05c00afc3bc --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/chatMessageAdded.graphqls @@ -0,0 +1,3 @@ +type Subscription { + chatMessageAdded(channelId: String, directTo: String): Message +} diff --git a/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.graphql b/packages/rocketchat-graphql/server/schemas/messages/deleteMessage.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/messages/deleteMessage.graphql rename to packages/rocketchat-graphql/server/schemas/messages/deleteMessage.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/messages/editMessage.graphql b/packages/rocketchat-graphql/server/schemas/messages/editMessage.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/messages/editMessage.graphql rename to packages/rocketchat-graphql/server/schemas/messages/editMessage.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/messages/messages.graphql b/packages/rocketchat-graphql/server/schemas/messages/messages.graphqls similarity index 81% rename from packages/rocketchat-graphql/server/schemas/messages/messages.graphql rename to packages/rocketchat-graphql/server/schemas/messages/messages.graphqls index 2b9774942e76..a81fe2186ca7 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/messages.graphql +++ b/packages/rocketchat-graphql/server/schemas/messages/messages.graphqls @@ -1,8 +1,8 @@ type Query { messages( channelId: String, - channelDetails: ChannelNameAndDirect, channelName: String, + directTo: String, cursor: String, count: Int, searchRegex: String, diff --git a/packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphql b/packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphql deleted file mode 100644 index 6f160fef1c94..000000000000 --- a/packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphql +++ /dev/null @@ -1,3 +0,0 @@ -type Mutation { - sendMessage(channelId: String!, content: String!): Message -} diff --git a/packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphqls b/packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphqls new file mode 100644 index 000000000000..78933ec6a763 --- /dev/null +++ b/packages/rocketchat-graphql/server/schemas/messages/sendMessage.graphqls @@ -0,0 +1,3 @@ +type Mutation { + sendMessage(channelId: String, directTo: String, content: String!): Message +} diff --git a/packages/rocketchat-graphql/server/schemas/users/User-type.graphql b/packages/rocketchat-graphql/server/schemas/users/User-type.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/users/User-type.graphql rename to packages/rocketchat-graphql/server/schemas/users/User-type.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.graphql b/packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.graphql rename to packages/rocketchat-graphql/server/schemas/users/UserStatus-enum.graphqls diff --git a/packages/rocketchat-graphql/server/schemas/users/setStatus.graphql b/packages/rocketchat-graphql/server/schemas/users/setStatus.graphqls similarity index 100% rename from packages/rocketchat-graphql/server/schemas/users/setStatus.graphql rename to packages/rocketchat-graphql/server/schemas/users/setStatus.graphqls From 388ba96aec4e4a86ee1436c709d9862c0afba736 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 6 Sep 2017 12:13:59 +0200 Subject: [PATCH 25/42] Add a ref to the issue with @accounts/graphql-api --- packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js b/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js index 8bd3dde10230..b94a295187f9 100644 --- a/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js +++ b/packages/rocketchat-graphql/server/mocks/accounts/graphql-api.js @@ -3,6 +3,7 @@ // It might be like that because of async/await, // maybe Promise is not wrapped with Fiber // See: https://github.com/meteor/meteor/blob/a362e20a37547362b581fed52f7171d022e83b62/packages/promise/server.js +// Opened issue: https://github.com/js-accounts/graphql/issues/16 export const authenticated = (Accounts, func) => (async(root, args, context, info) => { const authToken = context.authToken; From 8dffc899a447a31e876bd5b5b2e2d112f4c43ee5 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 6 Sep 2017 12:15:23 +0200 Subject: [PATCH 26/42] Back to merge-graphql-schemas@1.1.3 Since they fixed https://github.com/okgrow/merge-graphql-schemas/pull/83 --- packages/rocketchat-graphql/package.js | 2 +- packages/rocketchat-graphql/server/resolvers/accounts/index.js | 2 +- packages/rocketchat-graphql/server/resolvers/channels/index.js | 2 +- packages/rocketchat-graphql/server/resolvers/messages/index.js | 2 +- packages/rocketchat-graphql/server/resolvers/users/index.js | 2 +- packages/rocketchat-graphql/server/schema.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/rocketchat-graphql/package.js b/packages/rocketchat-graphql/package.js index 8d6ff940e0c1..436d212f3e89 100644 --- a/packages/rocketchat-graphql/package.js +++ b/packages/rocketchat-graphql/package.js @@ -29,6 +29,6 @@ Npm.depends({ 'graphql-subscriptions': '0.4.4', 'graphql-tools': '1.2.2', 'lodash.property': '4.4.2', - 'kamilkisiela-merge-graphql-schemas': '1.1.2', + 'merge-graphql-schemas': '1.1.3', 'subscriptions-transport-ws': '0.8.2' }); diff --git a/packages/rocketchat-graphql/server/resolvers/accounts/index.js b/packages/rocketchat-graphql/server/resolvers/accounts/index.js index 02aceb574911..e82a7077059b 100644 --- a/packages/rocketchat-graphql/server/resolvers/accounts/index.js +++ b/packages/rocketchat-graphql/server/resolvers/accounts/index.js @@ -1,6 +1,6 @@ import { createJSAccountsGraphQL } from '@accounts/graphql-api'; import { AccountsServer } from 'meteor/rocketchat:accounts'; -import { mergeTypes, mergeResolvers } from 'kamilkisiela-merge-graphql-schemas'; +import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; // queries import * as oauthProviders from './oauthProviders'; diff --git a/packages/rocketchat-graphql/server/resolvers/channels/index.js b/packages/rocketchat-graphql/server/resolvers/channels/index.js index 82a9dbff107d..063e9da41804 100644 --- a/packages/rocketchat-graphql/server/resolvers/channels/index.js +++ b/packages/rocketchat-graphql/server/resolvers/channels/index.js @@ -1,4 +1,4 @@ -import { mergeTypes, mergeResolvers } from 'kamilkisiela-merge-graphql-schemas'; +import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; // queries import * as channels from './channels'; diff --git a/packages/rocketchat-graphql/server/resolvers/messages/index.js b/packages/rocketchat-graphql/server/resolvers/messages/index.js index ad5fc67076e6..fb9728b19815 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/index.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/index.js @@ -1,4 +1,4 @@ -import { mergeTypes, mergeResolvers } from 'kamilkisiela-merge-graphql-schemas'; +import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; // queries import * as messages from './messages'; diff --git a/packages/rocketchat-graphql/server/resolvers/users/index.js b/packages/rocketchat-graphql/server/resolvers/users/index.js index 6de11371bf97..7647d5a5fdd6 100644 --- a/packages/rocketchat-graphql/server/resolvers/users/index.js +++ b/packages/rocketchat-graphql/server/resolvers/users/index.js @@ -1,4 +1,4 @@ -import { mergeTypes, mergeResolvers } from 'kamilkisiela-merge-graphql-schemas'; +import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; // mutations import * as setStatus from './setStatus'; diff --git a/packages/rocketchat-graphql/server/schema.js b/packages/rocketchat-graphql/server/schema.js index 1cbf6c38eeac..e8d3cbdd489e 100644 --- a/packages/rocketchat-graphql/server/schema.js +++ b/packages/rocketchat-graphql/server/schema.js @@ -1,5 +1,5 @@ import { makeExecutableSchema } from 'graphql-tools'; -import { mergeTypes, mergeResolvers } from 'kamilkisiela-merge-graphql-schemas'; +import { mergeTypes, mergeResolvers } from 'merge-graphql-schemas'; import * as channels from './resolvers/channels'; import * as messages from './resolvers/messages'; From 5619e785652193e0ce42f9db5dd3e0a7608cc178 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Fri, 8 Sep 2017 19:29:13 +0200 Subject: [PATCH 27/42] Add Authorization token to WebSocket connection --- .../.npm/package/npm-shrinkwrap.json | 20 +++++++++---------- packages/rocketchat-graphql/server/api.js | 7 +------ .../resolvers/messages/chatMessageAdded.js | 10 +++------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json index 10d14533cd41..d496fa3ccc45 100644 --- a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json @@ -291,11 +291,6 @@ "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz", "from": "jwt-decode@>=2.1.0 <3.0.0" }, - "kamilkisiela-merge-graphql-schemas": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/kamilkisiela-merge-graphql-schemas/-/kamilkisiela-merge-graphql-schemas-1.1.2.tgz", - "from": "kamilkisiela-merge-graphql-schemas@1.1.2" - }, "lodash": { "version": "4.17.4", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", @@ -336,6 +331,11 @@ "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", "from": "merge-descriptors@1.0.1" }, + "merge-graphql-schemas": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/merge-graphql-schemas/-/merge-graphql-schemas-1.1.3.tgz", + "from": "merge-graphql-schemas@1.1.3" + }, "methods": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", @@ -347,13 +347,13 @@ "from": "mime@1.3.4" }, "mime-db": { - "version": "1.29.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.29.0.tgz", - "from": "mime-db@>=1.29.0 <1.30.0" + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz", + "from": "mime-db@>=1.30.0 <1.31.0" }, "mime-types": { - "version": "2.1.16", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.16.tgz", + "version": "2.1.17", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz", "from": "mime-types@>=2.1.15 <2.2.0" }, "moment": { diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index 494429f52e97..ede3862d58c0 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -42,12 +42,7 @@ new SubscriptionServer({ schema: executableSchema, execute, subscribe, - onOperation: ({context}) => { - console.log('context', context); - return { - authToken: context.Authorization - }; - } + onConnect: (connectionParams) => ({ authToken: connectionParams.Authorization }) }, { path: '/subscriptions', diff --git a/packages/rocketchat-graphql/server/resolvers/messages/chatMessageAdded.js b/packages/rocketchat-graphql/server/resolvers/messages/chatMessageAdded.js index 08cb14bdb274..8a81c66a69b3 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/chatMessageAdded.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/chatMessageAdded.js @@ -29,18 +29,14 @@ function shouldPublish(message, { id, directTo }, username) { const resolver = { Subscription: { chatMessageAdded: { - subscribe: withFilter(() => pubsub.asyncIterator(CHAT_MESSAGE_SUBSCRIPTION_TOPIC), (payload, args, ctx) => { - // FIX: there's no authToken in context - // TODO: check if middleware applies to subscriptions, probably not. + subscribe: withFilter(() => pubsub.asyncIterator(CHAT_MESSAGE_SUBSCRIPTION_TOPIC), authenticated((payload, args, { user }) => { const channel = { id: args.channelId, directTo: args.directTo }; - console.log('context in sub', ctx); - - return shouldPublish(payload.chatMessageAdded, channel, ctx.user.username); - }) + return shouldPublish(payload.chatMessageAdded, channel, user.username); + })) } } }; From 04e2494d29e65d4f55c9ab38d03bfac015aa2392 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 12 Sep 2017 09:54:05 +0200 Subject: [PATCH 28/42] Fix an issue with Fiber (User.avatar) --- .../rocketchat-graphql/server/resolvers/users/User-type.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/rocketchat-graphql/server/resolvers/users/User-type.js b/packages/rocketchat-graphql/server/resolvers/users/User-type.js index f2c13fc58bf3..67d0e451925f 100644 --- a/packages/rocketchat-graphql/server/resolvers/users/User-type.js +++ b/packages/rocketchat-graphql/server/resolvers/users/User-type.js @@ -8,7 +8,8 @@ const resolver = { id: property('_id'), status: ({status}) => status.toUpperCase(), avatar: async({ _id }) => { - const avatar = RocketChat.models.Avatars.findOne({ + // XXX js-accounts/graphql#16 + const avatar = await RocketChat.models.Avatars.model.rawCollection().findOne({ userId: _id }, { fields: { url: 1 }}); From 9dd51b363d68e239185f9e0b90143dc135fe0427 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Tue, 12 Sep 2017 16:11:20 +0200 Subject: [PATCH 29/42] Meteor 1.5.2 --- .meteor/versions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.meteor/versions b/.meteor/versions index c608ae9d789f..8d8ebbff6657 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -42,7 +42,7 @@ ecmascript-runtime-server@0.4.1 edgee:slingshot@0.7.1 ejson@1.0.14 email@1.2.3 -emojione:emojione@3.0.3 +emojione:emojione@2.2.6 facebook-oauth@1.3.2 fastclick@1.0.13 francocatena:status@1.5.3 From 161f9a1b0ab368d21aadd4b3034f9a25d722a5b5 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Sat, 16 Sep 2017 22:24:01 +0200 Subject: [PATCH 30/42] Use a separate server for graphql subscriptions and fix channels.create (#2) * Use a separate server for graphql subscriptions * Fix an issue with channel creation in REST API --- packages/rocketchat-api/server/v1/channels.js | 8 ++-- packages/rocketchat-graphql/server/api.js | 42 ++++++++++++------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/packages/rocketchat-api/server/v1/channels.js b/packages/rocketchat-api/server/v1/channels.js index 86abc6ab38e6..1075a0f2be34 100644 --- a/packages/rocketchat-api/server/v1/channels.js +++ b/packages/rocketchat-api/server/v1/channels.js @@ -133,15 +133,15 @@ function createChannelValidator(params) { throw new Error('unauthorized'); } - if (!params.name.value) { + if (!params.name || !params.name.value) { throw new Error(`Param "${ params.name.key }" is required`); } - if (params.members.value && !_.isArray(params.members.value)) { + if (params.members && params.members.value && !_.isArray(params.members.value)) { throw new Error(`Param "${ params.members.key }" must be an array if provided`); } - if (params.customFields.value && !(typeof params.customFields.value === 'object')) { + if (params.customFields && params.customFields.value && !(typeof params.customFields.value === 'object')) { throw new Error(`Param "${ params.customFields.key }" must be an object if provided`); } } @@ -176,7 +176,7 @@ RocketChat.API.v1.addRoute('channels.create', { authRequired: true }, { let error; try { - RocketChat.API.create.validate({ + RocketChat.API.channels.create.validate({ user: { value: userId }, diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index ede3862d58c0..1b2177a653d9 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -10,11 +10,12 @@ import cors from 'cors'; import { executableSchema } from './schema'; +const subscriptionPort = 3100; + // the Meteor GraphQL server is an Express server const graphQLServer = express(); graphQLServer.use(cors()); -graphQLServer.use(bodyParser.urlencoded({ extended: true })); graphQLServer.use( '/graphql', @@ -33,20 +34,31 @@ graphQLServer.use( }) ); -graphQLServer.use('/graphiql', graphiqlExpress({ - endpointURL: '/graphql', - subscriptionsEndpoint: 'ws://localhost:3000/subscriptions' -})); - -new SubscriptionServer({ - schema: executableSchema, - execute, - subscribe, - onConnect: (connectionParams) => ({ authToken: connectionParams.Authorization }) -}, -{ - path: '/subscriptions', - server: WebApp.httpServer +graphQLServer.use( + '/graphiql', + graphiqlExpress({ + endpointURL: '/graphql', + subscriptionsEndpoint: `ws://localhost:${ subscriptionPort }` + }) +); + +function startSubscriptionServer() { + SubscriptionServer.create({ + schema: executableSchema, + execute, + subscribe, + onConnect: (connectionParams) => ({ authToken: connectionParams.Authorization }) + }, + { + port: subscriptionPort, + host: process.env.BIND_IP || '0.0.0.0' + }); + + console.log('GraphQL Subscription server runs on port:', subscriptionPort); +} + +WebApp.onListening(() => { + startSubscriptionServer(); }); // this binds the specified paths to the Express server running Apollo + GraphiQL From 85e15ff19d6db97fc0f8236c438f7315f4385987 Mon Sep 17 00:00:00 2001 From: Gabriel Delavald Date: Thu, 14 Dec 2017 19:19:36 -0200 Subject: [PATCH 31/42] Adds basic e2e tests for graphql --- package.json | 1 + .../.npm/package/npm-shrinkwrap.json | 134 ++++--- .../.npm/package/npm-shrinkwrap.json | 99 ++++- .../.npm/package/npm-shrinkwrap.json | 209 +++++----- .../.npm/package/npm-shrinkwrap.json | 365 +++++++++++------- .../server/resolvers/users/User-type.js | 6 +- .../rocketchat-livechat/app/package-lock.json | 12 +- tests/end-to-end/graphql/queries.js | 292 ++++++++++++++ 8 files changed, 799 insertions(+), 319 deletions(-) create mode 100644 tests/end-to-end/graphql/queries.js diff --git a/package.json b/package.json index eaabe38705d8..4845ba38d706 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "testunit-watch": "mocha --watch --opts ./mocha.opts \"`node -e \"console.log(require('./package.json').mocha.tests.join(' '))\"`\"", "coverage": "nyc -r html mocha --opts ./mocha.opts \"`node -e \"console.log(require('./package.json').mocha.tests.join(' '))\"`\"", "testunit": "mocha --opts ./mocha.opts \"`node -e \"console.log(require('./package.json').mocha.tests.join(' '))\"`\"", + "testgraphql": "mocha --opts ./mocha.opts tests/end-to-end/graphql/*.js", "version": "node .scripts/version.js", "set-version": "node .scripts/set-version.js", "release": "npm run set-version --silent" diff --git a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json index 9bee17427949..64d4dcb8e5b9 100644 --- a/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-accounts/.npm/package/npm-shrinkwrap.json @@ -1,243 +1,259 @@ { + "lockfileVersion": 1, "dependencies": { + "@accounts/common": { + "version": "0.0.18", + "resolved": "https://registry.npmjs.org/@accounts/common/-/common-0.0.18.tgz", + "integrity": "sha1-QB9Sd+tHk6qNBD8TUCituAh+FHs=" + }, + "@accounts/mongo": { + "version": "0.0.12", + "resolved": "https://registry.npmjs.org/@accounts/mongo/-/mongo-0.0.12.tgz", + "integrity": "sha1-n7UNmgn2vThw5u3ZYC/xHL0gxns=" + }, + "@accounts/server": { + "version": "0.0.18", + "resolved": "https://registry.npmjs.org/@accounts/server/-/server-0.0.18.tgz", + "integrity": "sha1-S7UCs0WZUkRgRbqXYyT5MnuLekQ=" + }, "addressparser": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/addressparser/-/addressparser-0.3.2.tgz", - "from": "addressparser@>=0.3.2 <0.4.0" + "integrity": "sha1-WYc/Nej89sc2HBAjkmHXbhU0i7I=" }, "babel-polyfill": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", - "from": "babel-polyfill@>=6.23.0 <7.0.0" + "integrity": "sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=" }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", - "from": "babel-runtime@>=6.26.0 <7.0.0", + "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", "dependencies": { "regenerator-runtime": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz", - "from": "regenerator-runtime@>=0.11.0 <0.12.0" + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" } } }, "base64url": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz", - "from": "base64url@>=2.0.0 <3.0.0" + "integrity": "sha1-6sFuA+oUOO/5Qj1puqNiYu0fcLs=" }, "bcryptjs": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz", - "from": "bcryptjs@>=2.4.0 <3.0.0" + "integrity": "sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms=" }, "bson": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/bson/-/bson-1.0.4.tgz", - "from": "bson@>=1.0.4 <1.1.0" + "integrity": "sha1-k8ENOeqltYQVy8QFLz5T5WKwtyw=" }, "buffer-equal-constant-time": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", - "from": "buffer-equal-constant-time@1.0.1" + "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" }, "buffer-shims": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/buffer-shims/-/buffer-shims-1.0.0.tgz", - "from": "buffer-shims@>=1.0.0 <1.1.0" + "integrity": "sha1-mXjOMXOIxkmth5MCjDR37wRKi1E=" }, "bufferjs": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/bufferjs/-/bufferjs-1.1.0.tgz", - "from": "bufferjs@1.1.0" + "integrity": "sha1-CV/6OcXmtAoheKEWnJ7/xYSnMgE=" }, "core-js": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.1.tgz", - "from": "core-js@>=2.5.0 <3.0.0" + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.3.tgz", + "integrity": "sha1-isw4NFgk8W2DZbfJtCWRaOjtYD4=" }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "from": "core-util-is@>=1.0.0 <1.1.0" + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "crypto": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/crypto/-/crypto-0.0.3.tgz", - "from": "crypto@>=0.0.3 <0.0.4" + "integrity": "sha1-RwqBuGvkxe4XrMggeh9TFa4g27A=" }, "ecdsa-sig-formatter": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz", - "from": "ecdsa-sig-formatter@1.0.9" + "integrity": "sha1-S8kmJ07Dtau1AW5+HWCSGsJisqE=" }, "emailjs": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/emailjs/-/emailjs-1.0.12.tgz", - "from": "emailjs@>=1.0.8 <2.0.0" + "integrity": "sha1-vWVZxRxJYxJSGGJtoJi+ci96HHI=" }, "encoding": { "version": "0.1.12", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", - "from": "encoding@>=0.1.0 <0.2.0" + "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=" }, "es6-promise": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.2.1.tgz", - "from": "es6-promise@3.2.1" + "integrity": "sha1-7FYjOGgDKQkgcXDDlEjiREndH8Q=" }, "hoek": { "version": "2.16.3", "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", - "from": "hoek@>=2.0.0 <3.0.0" + "integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=" }, "iconv-lite": { - "version": "0.4.18", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.18.tgz", - "from": "iconv-lite@>=0.4.13 <0.5.0" + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "from": "inherits@>=2.0.1 <2.1.0" + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "from": "isarray@>=1.0.0 <1.1.0" + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, "isemail": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/isemail/-/isemail-1.2.0.tgz", - "from": "isemail@>=1.0.0 <2.0.0" + "integrity": "sha1-vgPfjMPineTSxd9lASY/H6RZXpo=" }, "joi": { "version": "6.10.1", "resolved": "https://registry.npmjs.org/joi/-/joi-6.10.1.tgz", - "from": "joi@>=6.10.1 <7.0.0" + "integrity": "sha1-TVDDGAeRIgAP5fFq8f+OGRe3fgY=" }, "jsonwebtoken": { "version": "7.4.3", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.3.tgz", - "from": "jsonwebtoken@>=7.2.1 <8.0.0" + "integrity": "sha1-d/UCHeBYtgWheD+hKD6ZgS5kVjg=" }, "jwa": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz", - "from": "jwa@>=1.1.4 <2.0.0" + "integrity": "sha1-oFUs4CIHQs1S4VN3SjKQXDDnVuU=" }, "jws": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/jws/-/jws-3.1.4.tgz", - "from": "jws@>=3.1.4 <4.0.0" + "integrity": "sha1-+ei5M46KhHJ31kRLFGT2GIDgUKI=" }, "jwt-decode": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz", - "from": "jwt-decode@>=2.1.0 <3.0.0" + "integrity": "sha1-fYa9VmefWM5qhHBKZX3TkruoGnk=" }, "lodash": { "version": "4.17.4", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", - "from": "lodash@>=4.16.4 <5.0.0" + "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=" }, "lodash.once": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", - "from": "lodash.once@>=4.0.0 <5.0.0" + "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" }, "mimelib": { "version": "0.2.14", "resolved": "https://registry.npmjs.org/mimelib/-/mimelib-0.2.14.tgz", - "from": "mimelib@0.2.14", + "integrity": "sha1-KhqnJL0ZC4W9Um5jF6thBu39aDE=", "dependencies": { "addressparser": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/addressparser/-/addressparser-0.2.1.tgz", - "from": "addressparser@>=0.2.0 <0.3.0" + "integrity": "sha1-0RpbLu2gTP7+vfMZbBCuE9ts1gc=" } } }, "moment": { "version": "2.15.2", "resolved": "https://registry.npmjs.org/moment/-/moment-2.15.2.tgz", - "from": "moment@2.15.2" + "integrity": "sha1-G/3t9qbjRfMi/pVtXfW9CKjOhNw=" }, "mongodb": { - "version": "2.2.31", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.31.tgz", - "from": "mongodb@>=2.2.22 <3.0.0" + "version": "2.2.33", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.33.tgz", + "integrity": "sha1-tTfEcdNKZlG0jzb9vyl1A0Dgi1A=" }, "mongodb-core": { - "version": "2.1.15", - "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.15.tgz", - "from": "mongodb-core@2.1.15" + "version": "2.1.17", + "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.17.tgz", + "integrity": "sha1-pBizN6FKFJkPtRC5I97mqBMXPfg=" }, "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "from": "ms@>=2.0.0 <3.0.0" + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" }, "process-nextick-args": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", - "from": "process-nextick-args@>=1.0.6 <1.1.0" + "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" }, "readable-stream": { "version": "2.2.7", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.2.7.tgz", - "from": "readable-stream@2.2.7" + "integrity": "sha1-BwV6y+JGeyIELTb5jFrVBwVOlbE=" }, "regenerator-runtime": { "version": "0.10.5", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", - "from": "regenerator-runtime@>=0.10.5 <0.11.0" + "integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=" }, "require_optional": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", - "from": "require_optional@>=1.0.0 <1.1.0" + "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==" }, "resolve-from": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz", - "from": "resolve-from@>=2.0.0 <3.0.0" + "integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c=" }, "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "from": "safe-buffer@>=5.0.1 <6.0.0" + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" }, "semver": { "version": "5.4.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz", - "from": "semver@>=5.1.0 <6.0.0" + "integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg==" }, "starttls": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/starttls/-/starttls-1.0.1.tgz", - "from": "starttls@1.0.1" + "integrity": "sha1-5ggcJd5rF49adfjyccFIdEkYO0I=" }, "string_decoder": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "from": "string_decoder@>=1.0.0 <1.1.0" + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==" }, "topo": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/topo/-/topo-1.1.0.tgz", - "from": "topo@>=1.0.0 <2.0.0" + "integrity": "sha1-6ddRYV0buH3IZdsYL6HKCl71NtU=" }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "from": "util-deprecate@>=1.0.1 <1.1.0" + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "xtend": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "from": "xtend@>=4.0.1 <5.0.0" + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" } } } diff --git a/packages/rocketchat-google-vision/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-google-vision/.npm/package/npm-shrinkwrap.json index de48c301bb9f..a473ba9e56ed 100644 --- a/packages/rocketchat-google-vision/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-google-vision/.npm/package/npm-shrinkwrap.json @@ -1,6 +1,93 @@ { "lockfileVersion": 1, "dependencies": { + "@google-cloud/common": { + "version": "0.13.6", + "resolved": "https://registry.npmjs.org/@google-cloud/common/-/common-0.13.6.tgz", + "integrity": "sha1-qdjhN7xCmkSrqWif5qDkMxeE+FM=" + }, + "@google-cloud/common-grpc": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/@google-cloud/common-grpc/-/common-grpc-0.4.3.tgz", + "integrity": "sha512-A3nErp1qV8iCWPYQniBhot7Gx+kZHTAuRzOQyoPpfbv9pLmsvZgTWzVUg1/R1ncrirQElHUDhIFXPV+kr+UJAA==", + "dependencies": { + "dot-prop": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-2.4.0.tgz", + "integrity": "sha1-hI4o9/HVB0DGdHqzywdnBGK2+Jw=" + } + } + }, + "@google-cloud/storage": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@google-cloud/storage/-/storage-1.2.1.tgz", + "integrity": "sha1-oPLiCHG4YvDqZKkKxI/AiEXPlQU=" + }, + "@google-cloud/vision": { + "version": "0.11.5", + "resolved": "https://registry.npmjs.org/@google-cloud/vision/-/vision-0.11.5.tgz", + "integrity": "sha1-W9sS0ptVQsX7fbtelDLDmsrR9v4=" + }, + "@protobufjs/aspromise": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", + "integrity": "sha1-m4sMxmPWaafY9vXQiToU00jzD78=" + }, + "@protobufjs/base64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==" + }, + "@protobufjs/codegen": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz", + "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==" + }, + "@protobufjs/eventemitter": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz", + "integrity": "sha1-NVy8mLr61ZePntCV85diHx0Ga3A=" + }, + "@protobufjs/fetch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz", + "integrity": "sha1-upn7WYYUr2VwDBYZ/wbUVLDYTEU=" + }, + "@protobufjs/float": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", + "integrity": "sha1-Xp4avctz/Ap8uLKR33jIy9l7h9E=" + }, + "@protobufjs/inquire": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz", + "integrity": "sha1-/yAOPnzyQp4tyvwRQIKOjMY48Ik=" + }, + "@protobufjs/path": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", + "integrity": "sha1-bMKyDFya1q0NzP0hynZz2Nf79o0=" + }, + "@protobufjs/pool": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", + "integrity": "sha1-Cf0V8tbTq/qbZbw2ZQbWrXhG/1Q=" + }, + "@protobufjs/utf8": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", + "integrity": "sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=" + }, + "@types/long": { + "version": "3.0.32", + "resolved": "https://registry.npmjs.org/@types/long/-/long-3.0.32.tgz", + "integrity": "sha512-ZXyOOm83p7X8p3s0IYM3VeueNmHpkk/yMlP8CLeOnEcu6hIwPH7YjZBvhQkR0ZFS2DqZAxKtJ/M5fcuv3OU5BA==" + }, + "@types/node": { + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.5.1.tgz", + "integrity": "sha512-SrmAO+NhnsuG/6TychSl2VdxBZiw/d6V+8j+DFo8O3PwFi+QeYXWHhAw+b170aSc6zYab6/PjEWRZHIDN9mNUw==" + }, "ajv": { "version": "5.5.1", "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.1.tgz", @@ -353,9 +440,9 @@ "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" }, "grpc": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.7.2.tgz", - "integrity": "sha512-GH6xziNGjW8LAtqQ3HmYI7Tx8BIlr46iaMRXHfh46kkaOP6PNWUx47ULNTUlXSYR3P00d0Pl8uzodTLwPk805w==", + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.7.3.tgz", + "integrity": "sha512-7zXQJlDXMr/ZaDqdaIchgclViyoWo8GQxZSmFUAxR8GwSr28b6/BTgF221WG+2W693jpp74XJ/+I9DcPXsgt9Q==", "dependencies": { "abbrev": { "version": "1.0.9", @@ -1239,9 +1326,9 @@ "integrity": "sha512-lR3gD69osqm6EYLk9wB/G1W/laGWjzH90t1vEa2xuxHD5KUrSzp9pUSfTm+YC5Nxt2T8nMPEvKlhbQayU7bgFw==" }, "retry-request": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/retry-request/-/retry-request-3.3.0.tgz", - "integrity": "sha512-bCbvtnZkfgB2TnbKMUUxzSR5W4AJQyMD6D6UcCsE/wBTVmlsS59OrDQr4RKV/Kq1hiIBmUYlbxd9MZ0cfpjrAQ==" + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/retry-request/-/retry-request-3.3.1.tgz", + "integrity": "sha512-PjAmtWIxjNj4Co/6FRtBl8afRP3CxrrIAnUzb1dzydfROd+6xt7xAebFeskgQgkfFf8NmzrXIoaB3HxmswXyxw==" }, "rgb-hex": { "version": "1.0.0", diff --git a/packages/rocketchat-grant/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-grant/.npm/package/npm-shrinkwrap.json index d824bf98528a..0f2cc65af3df 100644 --- a/packages/rocketchat-grant/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-grant/.npm/package/npm-shrinkwrap.json @@ -1,536 +1,537 @@ { + "lockfileVersion": 1, "dependencies": { "accepts": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.3.tgz", - "from": "accepts@>=1.3.3 <1.4.0" + "integrity": "sha1-w8p0NJOGSMPg2cHjKN1otiLChMo=" }, "ajv": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/ajv/-/ajv-4.11.8.tgz", - "from": "ajv@>=4.9.1 <5.0.0" + "integrity": "sha1-gv+wKynmYq5TvcIK8VlHcGc5xTY=" }, "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "from": "array-flatten@1.1.1" + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, "asn1": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", - "from": "asn1@>=0.2.3 <0.3.0" + "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=" }, "assert-plus": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.2.0.tgz", - "from": "assert-plus@>=0.2.0 <0.3.0" + "integrity": "sha1-104bh+ev/A24qttwIfP+SBAasjQ=" }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "from": "asynckit@>=0.4.0 <0.5.0" + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, "aws-sign2": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.6.0.tgz", - "from": "aws-sign2@>=0.6.0 <0.7.0" + "integrity": "sha1-FDQt0428yU0OW4fXY81jYSwOeU8=" }, "aws4": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz", - "from": "aws4@>=1.2.1 <2.0.0" + "integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=" }, "bcrypt-pbkdf": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", - "from": "bcrypt-pbkdf@>=1.0.0 <2.0.0" + "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=" }, "boom": { "version": "2.10.1", "resolved": "https://registry.npmjs.org/boom/-/boom-2.10.1.tgz", - "from": "boom@>=2.0.0 <3.0.0" + "integrity": "sha1-OciRjO/1eZ+D+UkqhI9iWt0Mdm8=" }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "from": "caseless@>=0.12.0 <0.13.0" + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", - "from": "co@>=4.6.0 <5.0.0" + "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" }, "combined-stream": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", - "from": "combined-stream@>=1.0.5 <1.1.0" + "integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=" }, "content-disposition": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", - "from": "content-disposition@0.5.2" + "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" }, "content-type": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.2.tgz", - "from": "content-type@>=1.0.2 <1.1.0" + "integrity": "sha1-t9ETrueo3Se9IRM8TcJSnfFyHu0=" }, "cookie": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", - "from": "cookie@0.3.1" + "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" }, "cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", - "from": "cookie-signature@1.0.6" + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "from": "core-util-is@1.0.2" + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "crc": { "version": "3.4.4", "resolved": "https://registry.npmjs.org/crc/-/crc-3.4.4.tgz", - "from": "crc@3.4.4" + "integrity": "sha1-naHpgOO9RPxck79as9ozeNheRms=" }, "cryptiles": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz", - "from": "cryptiles@>=2.0.0 <3.0.0" + "integrity": "sha1-O9/s3GCBR8HGcgL6KR59ylnqo7g=" }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", - "from": "dashdash@>=1.12.0 <2.0.0", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", "dependencies": { "assert-plus": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "from": "assert-plus@>=1.0.0 <2.0.0" + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" } } }, "debug": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.7.tgz", - "from": "debug@2.6.7" + "integrity": "sha1-krrR9tBbu2u6Isyoi80OyJTChh4=" }, "deep-copy": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/deep-copy/-/deep-copy-1.2.0.tgz", - "from": "deep-copy@>=1.2.0 <2.0.0" + "integrity": "sha1-X7KnqV9UVUc9fOOaOS9Cw1FOEeg=" }, "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "from": "delayed-stream@>=1.0.0 <1.1.0" + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, "depd": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", - "from": "depd@>=1.1.0 <1.2.0" + "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" }, "destroy": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "from": "destroy@>=1.0.4 <1.1.0" + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, "ecc-jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", - "from": "ecc-jsbn@>=0.1.1 <0.2.0" + "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=" }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "from": "ee-first@1.1.1" + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, "encodeurl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz", - "from": "encodeurl@>=1.0.1 <1.1.0" + "integrity": "sha1-eePVhlU0aQn+bw9Fpd5oEDspTSA=" }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "from": "escape-html@>=1.0.3 <1.1.0" + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" }, "etag": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.0.tgz", - "from": "etag@>=1.8.0 <1.9.0" + "integrity": "sha1-b2Ma7zNtbEY2K1F2QETOIWvjwFE=" }, "express": { "version": "4.15.3", "resolved": "https://registry.npmjs.org/express/-/express-4.15.3.tgz", - "from": "express@4.15.3" + "integrity": "sha1-urZdDwOqgMNYQIly/HAPkWlEtmI=" }, "express-session": { "version": "1.15.4", "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.15.4.tgz", - "from": "express-session@1.15.4", + "integrity": "sha1-Xizc9t7+PB7aTpgPE7mGzFjPuVQ=", "dependencies": { "debug": { "version": "2.6.8", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "from": "debug@2.6.8" + "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=" } } }, "extend": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", - "from": "extend@>=3.0.0 <3.1.0" + "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=" }, "extsprintf": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", - "from": "extsprintf@1.3.0" + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" }, "finalhandler": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.3.tgz", - "from": "finalhandler@>=1.0.3 <1.1.0" + "integrity": "sha1-70fneVDpmXgOhgIqVg4yF+DQzIk=" }, "forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "from": "forever-agent@>=0.6.1 <0.7.0" + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" }, "form-data": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.1.4.tgz", - "from": "form-data@>=2.1.1 <2.2.0" + "integrity": "sha1-M8GDrPGTJ27KqYFDpp6Uv+4XUNE=" }, "forwarded": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.0.tgz", - "from": "forwarded@>=0.1.0 <0.2.0" + "integrity": "sha1-Ge+YdMSuHCl7zweP3mOgm2aoQ2M=" }, "fresh": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.0.tgz", - "from": "fresh@0.5.0" + "integrity": "sha1-9HTKXmqSRtb9jglTz6m5yAWvp44=" }, "getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", - "from": "getpass@>=0.1.1 <0.2.0", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", "dependencies": { "assert-plus": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "from": "assert-plus@>=1.0.0 <2.0.0" + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" } } }, "grant": { "version": "3.8.0", "resolved": "https://registry.npmjs.org/grant/-/grant-3.8.0.tgz", - "from": "grant@3.8.0" + "integrity": "sha512-Q8UN1j9JQmmb/Wf7PlYXJn92IjX9Tio21rEV5jOte/novOaZ/l0xMWNel7CDbRw0zqFEnYIIAyh1Cri2u3poUw==" }, "grant-express": { "version": "3.8.0", "resolved": "https://registry.npmjs.org/grant-express/-/grant-express-3.8.0.tgz", - "from": "grant-express@3.8.0" + "integrity": "sha512-Ph3SSr8vQTt9igZn4GAARjfOYPlB3nxngs0NwBqFNPbBdSPf+m5keEibfrP2GfeYK1GCYoz85BPQzQQZYbBzpQ==" }, "har-schema": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-1.0.5.tgz", - "from": "har-schema@>=1.0.5 <2.0.0" + "integrity": "sha1-0mMTX0MwfALGAq/I/pWXDAFRNp4=" }, "har-validator": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-4.2.1.tgz", - "from": "har-validator@>=4.2.1 <4.3.0" + "integrity": "sha1-M0gdDxu/9gDdID11gSpqX7oALio=" }, "hawk": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/hawk/-/hawk-3.1.3.tgz", - "from": "hawk@>=3.1.3 <3.2.0" + "integrity": "sha1-B4REvXwWQLD+VA0sm3PVlnjo4cQ=" }, "hoek": { "version": "2.16.3", "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", - "from": "hoek@>=2.0.0 <3.0.0" + "integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=" }, "http-errors": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.1.tgz", - "from": "http-errors@>=1.6.1 <1.7.0", + "integrity": "sha1-X4uO2YrKVFZWv1cplzh/kEpyIlc=", "dependencies": { "depd": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.0.tgz", - "from": "depd@1.1.0" + "integrity": "sha1-4b2Cxqq2ztlluXuIsX7T5SjKGMM=" } } }, "http-signature": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.1.1.tgz", - "from": "http-signature@>=1.1.0 <1.2.0" + "integrity": "sha1-33LiZwZs0Kxn+3at+OE0qPvPkb8=" }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "from": "inherits@2.0.3" + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "ipaddr.js": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.4.0.tgz", - "from": "ipaddr.js@1.4.0" + "integrity": "sha1-KWrKh4qCGBbluF0KKFqZvP9FgvA=" }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", - "from": "is-typedarray@>=1.0.0 <1.1.0" + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" }, "isstream": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "from": "isstream@>=0.1.2 <0.2.0" + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" }, "jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "from": "jsbn@>=0.1.0 <0.2.0" + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, "json-schema": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", - "from": "json-schema@0.2.3" + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" }, "json-stable-stringify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz", - "from": "json-stable-stringify@>=1.0.1 <2.0.0" + "integrity": "sha1-mnWdOcXy/1A/1TAGRu1EX4jE+a8=" }, "json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "from": "json-stringify-safe@>=5.0.1 <5.1.0" + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" }, "jsonify": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", - "from": "jsonify@>=0.0.0 <0.1.0" + "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=" }, "jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", - "from": "jsprim@>=1.2.2 <2.0.0", + "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", "dependencies": { "assert-plus": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "from": "assert-plus@1.0.0" + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" } } }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "from": "media-typer@0.3.0" + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" }, "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "from": "merge-descriptors@1.0.1" + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" }, "methods": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "from": "methods@>=1.1.2 <1.2.0" + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" }, "mime": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz", - "from": "mime@1.3.4" + "integrity": "sha1-EV+eO2s9rylZmDyzjxSaLUDrXVM=" }, "mime-db": { "version": "1.29.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.29.0.tgz", - "from": "mime-db@>=1.29.0 <1.30.0" + "integrity": "sha1-SNJtI1WJZRcErFkWygYAGRQmaHg=" }, "mime-types": { "version": "2.1.16", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.16.tgz", - "from": "mime-types@>=2.1.11 <2.2.0" + "integrity": "sha1-K4WKUuXs1RbbiXrCvodIeDBpjiM=" }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "from": "ms@2.0.0" + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "negotiator": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", - "from": "negotiator@0.6.1" + "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" }, "oauth-sign": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", - "from": "oauth-sign@>=0.8.1 <0.9.0" + "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=" }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "from": "on-finished@>=2.3.0 <2.4.0" + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=" }, "on-headers": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.1.tgz", - "from": "on-headers@>=1.0.1 <1.1.0" + "integrity": "sha1-ko9dD0cNSTQmUepnlLCFfBAGk/c=" }, "parseurl": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.1.tgz", - "from": "parseurl@>=1.3.1 <1.4.0" + "integrity": "sha1-yKuMkiO6NIiKpkopeyiFO+wY2lY=" }, "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "from": "path-to-regexp@0.1.7" + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" }, "performance-now": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-0.2.0.tgz", - "from": "performance-now@>=0.2.0 <0.3.0" + "integrity": "sha1-M+8wxcd9TqIcWlOGnZG1bY8lVeU=" }, "proxy-addr": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.5.tgz", - "from": "proxy-addr@>=1.1.4 <1.2.0" + "integrity": "sha1-ccDuOxAt4/IC87ZPYI0XP8uhqRg=" }, "punycode": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", - "from": "punycode@>=1.4.1 <2.0.0" + "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" }, "qs": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz", - "from": "qs@6.4.0" + "integrity": "sha1-E+JtKK1rD/qpExLNO/cI7TUecjM=" }, "random-bytes": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz", - "from": "random-bytes@>=1.0.0 <1.1.0" + "integrity": "sha1-T2ih3Arli9P7lYSMMDJNt11kNgs=" }, "range-parser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", - "from": "range-parser@>=1.2.0 <1.3.0" + "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" }, "request": { "version": "2.81.0", "resolved": "https://registry.npmjs.org/request/-/request-2.81.0.tgz", - "from": "request@2.81.0" + "integrity": "sha1-xpKJRqDgbF+Nb4qTM0af/aRimKA=" }, "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "from": "safe-buffer@>=5.0.1 <6.0.0" + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" }, "send": { "version": "0.15.3", "resolved": "https://registry.npmjs.org/send/-/send-0.15.3.tgz", - "from": "send@0.15.3" + "integrity": "sha1-UBP5+ZAj31DRvZiSwZ4979HVMwk=" }, "serve-static": { "version": "1.12.3", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.12.3.tgz", - "from": "serve-static@1.12.3" + "integrity": "sha1-n0uhni8wMMVH+K+ZEHg47DjVseI=" }, "setprototypeof": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", - "from": "setprototypeof@1.0.3" + "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" }, "sntp": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", - "from": "sntp@>=1.0.0 <2.0.0" + "integrity": "sha1-ZUEYTMkK7qbG57NeJlkIJEPGYZg=" }, "sshpk": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz", - "from": "sshpk@>=1.7.0 <2.0.0", + "integrity": "sha1-US322mKHFEMW3EwY/hzx2UBzm+M=", "dependencies": { "assert-plus": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "from": "assert-plus@>=1.0.0 <2.0.0" + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" } } }, "statuses": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", - "from": "statuses@>=1.3.1 <1.4.0" + "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", - "from": "stringstream@>=0.0.4 <0.1.0" + "integrity": "sha1-TkhM1N5aC7vuGORjB3EKioFiGHg=" }, "tough-cookie": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.2.tgz", - "from": "tough-cookie@>=2.3.0 <2.4.0" + "integrity": "sha1-8IH3bkyFcg5sN6X6ztc3FQ2EByo=" }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "from": "tunnel-agent@>=0.6.0 <0.7.0" + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=" }, "tweetnacl": { "version": "0.14.5", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "from": "tweetnacl@>=0.14.0 <0.15.0" + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, "type-is": { "version": "1.6.15", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", - "from": "type-is@>=1.6.15 <1.7.0" + "integrity": "sha1-yrEPtJCeRByChC6v4a1kbIGARBA=" }, "uid-safe": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", - "from": "uid-safe@>=2.1.4 <2.2.0" + "integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==" }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "from": "unpipe@>=1.0.0 <1.1.0" + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" }, "utils-merge": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz", - "from": "utils-merge@1.0.0" + "integrity": "sha1-ApT7kiu5N1FTVBxPcJYjHyh8ivg=" }, "uuid": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", - "from": "uuid@>=3.0.0 <4.0.0" + "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==" }, "vary": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.1.tgz", - "from": "vary@>=1.1.1 <1.2.0" + "integrity": "sha1-Z1Neu2lMHVIldFeYRmUyP1h+jTc=" }, "verror": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", - "from": "verror@1.10.0", + "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", "dependencies": { "assert-plus": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "from": "assert-plus@>=1.0.0 <2.0.0" + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" } } } diff --git a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json index d496fa3ccc45..ebd390267c54 100644 --- a/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json +++ b/packages/rocketchat-graphql/.npm/package/npm-shrinkwrap.json @@ -1,507 +1,590 @@ { + "lockfileVersion": 1, "dependencies": { + "@accounts/common": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/@accounts/common/-/common-0.0.4.tgz", + "integrity": "sha1-xaPs4coEYr38Au1JWWLeBhmiQ5Y=" + }, + "@accounts/graphql-api": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@accounts/graphql-api/-/graphql-api-0.1.1.tgz", + "integrity": "sha1-Dg6PHFumsZce9PIjnlnJRyWRtpo=" + }, + "@accounts/server": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/@accounts/server/-/server-0.0.4.tgz", + "integrity": "sha1-5UU5kczficvmSVxuHK1BPEHgLJM=" + }, + "@types/graphql": { + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/@types/graphql/-/graphql-0.9.4.tgz", + "integrity": "sha512-ob2dps4itT/Le5DbxjssBXtBnloDIRUbkgtAvaB42mJ8pVIWMRuURD9WjnhaEGZ4Ql/EryXMQWeU8Y0EU73QLw==" + }, "accepts": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.4.tgz", - "from": "accepts@>=1.3.3 <1.4.0" + "integrity": "sha1-hiRnWMfdbSGmR0/whKR0DsBesh8=" + }, + "apollo-cache-control": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/apollo-cache-control/-/apollo-cache-control-0.0.7.tgz", + "integrity": "sha512-DoMTr3uTC5Cx9ukSO63wlzHD15C37FwZuoOZEu+m/UTzVFKQ4PnlBKzwZ0H2+iIwcdSulV0xte6Z3wBe9lHAOA==" }, "apollo-server-core": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/apollo-server-core/-/apollo-server-core-1.1.0.tgz", - "from": "apollo-server-core@>=1.1.0 <2.0.0" + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/apollo-server-core/-/apollo-server-core-1.3.0.tgz", + "integrity": "sha1-p50ppw6BUKqKAUMjThFZS6QczI0=" }, "apollo-server-express": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/apollo-server-express/-/apollo-server-express-1.1.2.tgz", - "from": "apollo-server-express@1.1.2" + "integrity": "sha1-aTPHf+XfuafzDdOTI5rZlTphPNk=" }, "apollo-server-module-graphiql": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/apollo-server-module-graphiql/-/apollo-server-module-graphiql-1.1.2.tgz", - "from": "apollo-server-module-graphiql@>=1.1.2 <2.0.0" + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/apollo-server-module-graphiql/-/apollo-server-module-graphiql-1.3.0.tgz", + "integrity": "sha1-B3u4x78pL2EoxsltWcIJZEWwhO8=" }, "apollo-tracing": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/apollo-tracing/-/apollo-tracing-0.0.7.tgz", - "from": "apollo-tracing@>=0.0.7 <0.0.8" + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/apollo-tracing/-/apollo-tracing-0.1.1.tgz", + "integrity": "sha512-OrL0SYpmwNs6R339y7Is6PppOkyooMB1iLSN+HAp1FdBycQ88SqVV5Dqjxb4Du+TrMyyJLHfR5BAENZSFQyWGQ==" }, "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "from": "array-flatten@1.1.1" + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" + }, + "async-limiter": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", + "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" }, "babel-polyfill": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", - "from": "babel-polyfill@>=6.23.0 <7.0.0", + "integrity": "sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=", "dependencies": { "regenerator-runtime": { "version": "0.10.5", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", - "from": "regenerator-runtime@>=0.10.5 <0.11.0" + "integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=" } } }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", - "from": "babel-runtime@>=6.23.0 <7.0.0" + "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=" }, "backo2": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", - "from": "backo2@>=1.0.2 <2.0.0" + "integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc=" }, "base64url": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz", - "from": "base64url@>=2.0.0 <3.0.0" + "integrity": "sha1-6sFuA+oUOO/5Qj1puqNiYu0fcLs=" }, "bcryptjs": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz", - "from": "bcryptjs@>=2.4.0 <3.0.0" + "integrity": "sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms=" }, "body-parser": { "version": "1.17.2", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.17.2.tgz", - "from": "body-parser@1.17.2" + "integrity": "sha1-+IkqvI+eYn1Crtr7yma/WrmRBO4=" }, "buffer-equal-constant-time": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", - "from": "buffer-equal-constant-time@1.0.1" + "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" }, "bytes": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-2.4.0.tgz", - "from": "bytes@2.4.0" + "integrity": "sha1-fZcZb51br39pNeJZhVSe3SpsIzk=" }, "content-disposition": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", - "from": "content-disposition@0.5.2" + "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" }, "content-type": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.2.tgz", - "from": "content-type@>=1.0.2 <1.1.0" + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" }, "cookie": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", - "from": "cookie@0.3.1" + "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" }, "cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", - "from": "cookie-signature@1.0.6" + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, "core-js": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.1.tgz", - "from": "core-js@>=2.4.0 <3.0.0" + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.3.tgz", + "integrity": "sha1-isw4NFgk8W2DZbfJtCWRaOjtYD4=" }, "cors": { "version": "2.8.4", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.4.tgz", - "from": "cors@2.8.4" + "integrity": "sha1-K9OB8usgECAQXNUOpZ2mMJBpRoY=" }, "crypto": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/crypto/-/crypto-0.0.3.tgz", - "from": "crypto@>=0.0.3 <0.0.4" + "integrity": "sha1-RwqBuGvkxe4XrMggeh9TFa4g27A=" }, "debug": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.7.tgz", - "from": "debug@2.6.7" + "integrity": "sha1-krrR9tBbu2u6Isyoi80OyJTChh4=", + "dependencies": { + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } }, "deepmerge": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-1.5.1.tgz", - "from": "deepmerge@>=1.3.2 <2.0.0" + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-1.5.2.tgz", + "integrity": "sha512-95k0GDqvBjZavkuvzx/YqVLv/6YYa17fz6ILMSf7neqQITCPbnfEnQvEgMPNjH4kgobe7+WIL0yJEHku+H3qtQ==" }, "depd": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", - "from": "depd@>=1.1.0 <1.2.0" + "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" }, "deprecated-decorator": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz", - "from": "deprecated-decorator@>=0.1.6 <0.2.0" + "integrity": "sha1-AJZjF7ehL+kvPMgx91g68ym4bDc=" }, "destroy": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "from": "destroy@>=1.0.4 <1.1.0" + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, "ecdsa-sig-formatter": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz", - "from": "ecdsa-sig-formatter@1.0.9" + "integrity": "sha1-S8kmJ07Dtau1AW5+HWCSGsJisqE=" }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "from": "ee-first@1.1.1" + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, "encodeurl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.1.tgz", - "from": "encodeurl@>=1.0.1 <1.1.0" + "integrity": "sha1-eePVhlU0aQn+bw9Fpd5oEDspTSA=" }, "es6-promise": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.1.1.tgz", - "from": "es6-promise@>=4.0.5 <5.0.0" + "integrity": "sha512-OaU1hHjgJf+b0NzsxCg7NdIYERD6Hy/PEmFLTjw+b65scuisG3Kt4QoTvJ66BBkPZ581gr0kpoVzKnxniM8nng==" }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "from": "escape-html@>=1.0.3 <1.1.0" + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" }, "etag": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.0.tgz", - "from": "etag@>=1.8.0 <1.9.0" + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" }, "eventemitter3": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-2.0.3.tgz", - "from": "eventemitter3@>=2.0.3 <3.0.0" + "integrity": "sha1-teEHm1n7XhuidxwKmTvgYKWMmbo=" }, "express": { "version": "4.15.4", "resolved": "https://registry.npmjs.org/express/-/express-4.15.4.tgz", - "from": "express@4.15.4", + "integrity": "sha1-Ay4iU0ic+PzgJma+yj0R7XotrtE=", "dependencies": { "debug": { "version": "2.6.8", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "from": "debug@2.6.8" + "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "qs": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.0.tgz", - "from": "qs@6.5.0" + "integrity": "sha512-fjVFjW9yhqMhVGwRExCXLhJKrLlkYSaxNWdyc9rmHlrVZbk35YHH312dFd7191uQeXkI3mKLZTIbSvIeFwFemg==" + }, + "statuses": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", + "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" } } }, "finalhandler": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.4.tgz", - "from": "finalhandler@>=1.0.4 <1.1.0", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.6.tgz", + "integrity": "sha1-AHrqM9Gk0+QgF/YkhIrVjSEvgU8=", "dependencies": { "debug": { - "version": "2.6.8", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "from": "debug@2.6.8" + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "statuses": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", + "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" } } }, "forwarded": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.0.tgz", - "from": "forwarded@>=0.1.0 <0.2.0" + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", + "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" }, "fresh": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.0.tgz", - "from": "fresh@0.5.0" + "integrity": "sha1-9HTKXmqSRtb9jglTz6m5yAWvp44=" }, "graphql": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/graphql/-/graphql-0.10.3.tgz", - "from": "graphql@0.10.3" + "integrity": "sha1-wxOv1VGOZzNRvuGPtj4qDkh0B6s=" + }, + "graphql-extensions": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/graphql-extensions/-/graphql-extensions-0.0.5.tgz", + "integrity": "sha512-IbgYhKIyI60Nio/uJjkkiXaOZ2fI8ynAyzcA/okD0iuKzBdWX4Tn6tidMLgd16Bf2v3TtNnyXnN0F2BJDs6e4A==" }, "graphql-subscriptions": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-0.4.4.tgz", - "from": "graphql-subscriptions@0.4.4" + "integrity": "sha512-hqfUsZv39qmK4SEoKMnTO05U4EVvIeAD4ai5ztE9gCl4hEdeaF2Q5gvF80ONQQAnkys4odzxWYd2tBLS/cWl8g==" }, "graphql-tag": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.4.2.tgz", - "from": "graphql-tag@>=2.4.2 <3.0.0" + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.6.0.tgz", + "integrity": "sha1-D7G59tZlEmPEejQg6CeRDm/tOVI=" }, "graphql-tools": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-1.2.2.tgz", - "from": "graphql-tools@1.2.2" + "integrity": "sha512-FBcpceJMOYq8PEI8c40S5vAiCtwWh9vSrJc4DoanAiQOLC8DOXaZ8nY+3+/AwHRur+R+zDprGoL14QqcWr0RrA==" }, "hoek": { "version": "2.16.3", "resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz", - "from": "hoek@>=2.0.0 <3.0.0" + "integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0=" }, "http-errors": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", - "from": "http-errors@>=1.6.1 <1.7.0" + "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=" }, "iconv-lite": { "version": "0.4.15", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.15.tgz", - "from": "iconv-lite@0.4.15" + "integrity": "sha1-/iZaIYrGpXz+hUkn6dBMGYJe3es=" }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "from": "inherits@2.0.3" + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "ipaddr.js": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.4.0.tgz", - "from": "ipaddr.js@1.4.0" + "integrity": "sha1-KWrKh4qCGBbluF0KKFqZvP9FgvA=" }, "isemail": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/isemail/-/isemail-1.2.0.tgz", - "from": "isemail@>=1.0.0 <2.0.0" + "integrity": "sha1-vgPfjMPineTSxd9lASY/H6RZXpo=" }, "iterall": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.1.1.tgz", - "from": "iterall@>=1.1.0 <2.0.0" + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.1.3.tgz", + "integrity": "sha512-Cu/kb+4HiNSejAPhSaN1VukdNTTi/r4/e+yykqjlG/IW+1gZH5b4+Bq3whDX4tvbYugta3r8KTMUiqT3fIGxuQ==" }, "joi": { "version": "6.10.1", "resolved": "https://registry.npmjs.org/joi/-/joi-6.10.1.tgz", - "from": "joi@>=6.10.1 <7.0.0" + "integrity": "sha1-TVDDGAeRIgAP5fFq8f+OGRe3fgY=" }, "jsonwebtoken": { "version": "7.4.3", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.3.tgz", - "from": "jsonwebtoken@>=7.2.1 <8.0.0" + "integrity": "sha1-d/UCHeBYtgWheD+hKD6ZgS5kVjg=" }, "jwa": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz", - "from": "jwa@>=1.1.4 <2.0.0" + "integrity": "sha1-oFUs4CIHQs1S4VN3SjKQXDDnVuU=" }, "jws": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/jws/-/jws-3.1.4.tgz", - "from": "jws@>=3.1.4 <4.0.0" + "integrity": "sha1-+ei5M46KhHJ31kRLFGT2GIDgUKI=" }, "jwt-decode": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz", - "from": "jwt-decode@>=2.1.0 <3.0.0" + "integrity": "sha1-fYa9VmefWM5qhHBKZX3TkruoGnk=" }, "lodash": { "version": "4.17.4", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", - "from": "lodash@>=4.16.4 <5.0.0" + "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=" }, "lodash.assign": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz", - "from": "lodash.assign@>=4.2.0 <5.0.0" + "integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=" }, "lodash.isobject": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/lodash.isobject/-/lodash.isobject-3.0.2.tgz", - "from": "lodash.isobject@>=3.0.2 <4.0.0" + "integrity": "sha1-PI+41bW/S/kK4G4U8qUwpO2TXh0=" }, "lodash.isstring": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", - "from": "lodash.isstring@>=4.0.1 <5.0.0" + "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=" }, "lodash.once": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", - "from": "lodash.once@>=4.0.0 <5.0.0" + "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" }, "lodash.property": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.property/-/lodash.property-4.4.2.tgz", - "from": "lodash.property@4.4.2" + "integrity": "sha1-2gcSSCHGQJ0CXzDbjfhRMUUVv/4=" }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "from": "media-typer@0.3.0" + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" }, "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "from": "merge-descriptors@1.0.1" + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" }, "merge-graphql-schemas": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/merge-graphql-schemas/-/merge-graphql-schemas-1.1.3.tgz", - "from": "merge-graphql-schemas@1.1.3" + "integrity": "sha512-1e5tkvITcq5EtnCoSmZz9i6YBBZYBn5/QBD1YIpiG1dSzyuz+YuZTU5RY1voocljrPYzr1Of2tWNRy+CYaRZTA==" }, "methods": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "from": "methods@>=1.1.2 <1.2.0" + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" }, "mime": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz", - "from": "mime@1.3.4" + "integrity": "sha1-EV+eO2s9rylZmDyzjxSaLUDrXVM=" }, "mime-db": { "version": "1.30.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz", - "from": "mime-db@>=1.30.0 <1.31.0" + "integrity": "sha1-dMZD2i3Z1qRTmZY0ZbJtXKfXHwE=" }, "mime-types": { "version": "2.1.17", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz", - "from": "mime-types@>=2.1.15 <2.2.0" + "integrity": "sha1-Cdejk/A+mVp5+K+Fe3Cp4KsWVXo=" }, "moment": { - "version": "2.18.1", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.18.1.tgz", - "from": "moment@>=2.0.0 <3.0.0" + "version": "2.19.4", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.19.4.tgz", + "integrity": "sha512-1xFTAknSLfc47DIxHDUbnJWC+UwgWxATmymaxIPQpmMh7LBm7ZbwVEsuushqwL2GYZU0jie4xO+TK44hJPjNSQ==" }, "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "from": "ms@>=2.0.0 <3.0.0" + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" }, "negotiator": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", - "from": "negotiator@0.6.1" + "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "from": "object-assign@>=4.0.0 <5.0.0" + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "from": "on-finished@>=2.3.0 <2.4.0" + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=" }, "parseurl": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.1.tgz", - "from": "parseurl@>=1.3.1 <1.4.0" + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", + "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" }, "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "from": "path-to-regexp@0.1.7" + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" }, "proxy-addr": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.1.5.tgz", - "from": "proxy-addr@>=1.1.5 <1.2.0" + "integrity": "sha1-ccDuOxAt4/IC87ZPYI0XP8uhqRg=" }, "qs": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz", - "from": "qs@6.4.0" + "integrity": "sha1-E+JtKK1rD/qpExLNO/cI7TUecjM=" }, "range-parser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", - "from": "range-parser@>=1.2.0 <1.3.0" + "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" }, "raw-body": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.2.0.tgz", - "from": "raw-body@>=2.2.0 <2.3.0" + "integrity": "sha1-mUl2z2pQlqQRYoQEkvC9xdbn+5Y=" }, "regenerator-runtime": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz", - "from": "regenerator-runtime@>=0.11.0 <0.12.0" + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", + "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==" }, "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "from": "safe-buffer@>=5.0.1 <6.0.0" + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" }, "send": { "version": "0.15.4", "resolved": "https://registry.npmjs.org/send/-/send-0.15.4.tgz", - "from": "send@0.15.4", + "integrity": "sha1-mF+qPihLAnPHkzZKNcZze9k5Bbk=", "dependencies": { "debug": { "version": "2.6.8", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "from": "debug@2.6.8" + "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "statuses": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", + "integrity": "sha1-+vUbnrdKrvOzrPStX2Gr8ky3uT4=" } } }, "serve-static": { "version": "1.12.4", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.12.4.tgz", - "from": "serve-static@1.12.4" + "integrity": "sha1-m2qpjutyU8Tu3Ewfb9vKYJkBqWE=" }, "setprototypeof": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", - "from": "setprototypeof@1.0.3" + "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, + "source-map-support": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.0.tgz", + "integrity": "sha512-vUoN3I7fHQe0R/SJLKRdKYuEdRGogsviXFkHHo17AWaTGv17VLnxw+CFXvqy+y4ORZ3doWLQcxRYfwKrsd/H7Q==" }, "statuses": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz", - "from": "statuses@>=1.3.1 <2.0.0" + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", + "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" }, "subscriptions-transport-ws": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/subscriptions-transport-ws/-/subscriptions-transport-ws-0.8.2.tgz", - "from": "subscriptions-transport-ws@0.8.2" + "integrity": "sha512-bp0XR7ccnOspEFUKnmvTRN2VtrFdB4PqCWe7eooTY2fMwjBcm1kYkikWW/lo/d37yQ/BYUA+v0GPsyBakpc0OQ==" }, "symbol-observable": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.0.4.tgz", - "from": "symbol-observable@>=1.0.4 <2.0.0" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.1.0.tgz", + "integrity": "sha512-dQoid9tqQ+uotGhuTKEY11X4xhyYePVnqGSoSm3OGKh2E8LZ6RPULp1uXTctk33IeERlrRJYoVSBglsL05F5Uw==" }, "topo": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/topo/-/topo-1.1.0.tgz", - "from": "topo@>=1.0.0 <2.0.0" + "integrity": "sha1-6ddRYV0buH3IZdsYL6HKCl71NtU=" }, "type-is": { "version": "1.6.15", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", - "from": "type-is@>=1.6.15 <1.7.0" + "integrity": "sha1-yrEPtJCeRByChC6v4a1kbIGARBA=" }, "ultron": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.0.tgz", - "from": "ultron@>=1.1.0 <1.2.0" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", + "integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==" }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "from": "unpipe@1.0.0" + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" }, "utils-merge": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz", - "from": "utils-merge@1.0.0" + "integrity": "sha1-ApT7kiu5N1FTVBxPcJYjHyh8ivg=" }, "uuid": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", - "from": "uuid@>=3.0.1 <4.0.0" + "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==" }, "vary": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.1.tgz", - "from": "vary@>=1.0.0 <2.0.0" + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" }, "ws": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-3.1.0.tgz", - "from": "ws@>=3.0.0 <4.0.0" + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.2.tgz", + "integrity": "sha512-t+WGpsNxhMR4v6EClXS8r8km5ZljKJzyGhJf7goJz9k5Ye3+b5Bvno5rjqPuIBn5mnn5GBb7o8IrIWHxX1qOLQ==" }, "xtend": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "from": "xtend@>=4.0.1 <5.0.0" + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" } } } diff --git a/packages/rocketchat-graphql/server/resolvers/users/User-type.js b/packages/rocketchat-graphql/server/resolvers/users/User-type.js index 67d0e451925f..d768b78ab7f8 100644 --- a/packages/rocketchat-graphql/server/resolvers/users/User-type.js +++ b/packages/rocketchat-graphql/server/resolvers/users/User-type.js @@ -17,9 +17,9 @@ const resolver = { return avatar.url; } }, - channels: ({ _id }) => { - return RocketChat.models.Rooms.findBySubscriptionUserId(_id).fetch(); - }, + channels: Meteor.bindEnvironment(async({ _id }) => { + return await RocketChat.models.Rooms.findBySubscriptionUserId(_id).fetch(); + }), directMessages: ({ username }) => { return RocketChat.models.Rooms.findByTypeContainingUsername('d', username).fetch(); } diff --git a/packages/rocketchat-livechat/app/package-lock.json b/packages/rocketchat-livechat/app/package-lock.json index ca28ccbd474c..f71129f9bfcb 100644 --- a/packages/rocketchat-livechat/app/package-lock.json +++ b/packages/rocketchat-livechat/app/package-lock.json @@ -28,7 +28,7 @@ "aproba": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==" + "integrity": "sha1-aALmJk79GMeQobDVF/DyYnvyyUo=" }, "are-we-there-yet": { "version": "1.1.4", @@ -180,7 +180,7 @@ "boom": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/boom/-/boom-5.2.0.tgz", - "integrity": "sha512-Z5BTk6ZRe4tXXQlkqftmsAUANpXmuwlsF5Oov8ThoMbQRzdGTA1ngYRW160GexgOgjsFOKJz0LYhoNi+2AMBUw==", + "integrity": "sha1-XdnabuOl8wIHdDYpDLcX0/SlTgI=", "requires": { "hoek": "4.2.0" } @@ -351,7 +351,7 @@ "hawk": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/hawk/-/hawk-6.0.2.tgz", - "integrity": "sha512-miowhl2+U7Qle4vdLqDdPt9m09K6yZhkLDTWGoUiUzrQCn+mHHSmfJgAyGaLRZbPmTqfFFjRV1QWCW0VWUJBbQ==", + "integrity": "sha1-r02RTrBl+bXOTZ0RwcshJu7MMDg=", "requires": { "boom": "4.3.1", "cryptiles": "3.1.2", @@ -362,7 +362,7 @@ "hoek": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/hoek/-/hoek-4.2.0.tgz", - "integrity": "sha512-v0XCLxICi9nPfYrS9RL8HbYnXi9obYAeLbSP00BmnZwCK9+Ih9WOjoZ8YoHCoav2csqn4FOz4Orldsy2dmDwmQ==" + "integrity": "sha1-ctnQdU9/4lyi0BrY+PmpRJqJUm0=" }, "http-signature": { "version": "1.2.0", @@ -603,7 +603,7 @@ "qs": { "version": "6.5.1", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", - "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" + "integrity": "sha1-NJzfbu+J7EXBLX1es/wMhwNDptg=" }, "rc": { "version": "1.2.2", @@ -674,7 +674,7 @@ "rimraf": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", - "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", + "integrity": "sha1-LtgVDSShbqhlHm1u8PR8QVjOejY=", "requires": { "glob": "7.1.2" } diff --git a/tests/end-to-end/graphql/queries.js b/tests/end-to-end/graphql/queries.js new file mode 100644 index 000000000000..e348edc8e921 --- /dev/null +++ b/tests/end-to-end/graphql/queries.js @@ -0,0 +1,292 @@ +/* eslint-env mocha */ + +const supertest = require('supertest'); +const request = supertest('http://localhost:3000'); + +const user = {username: 'rocketchat.internal.admin.test', password: 'rocketchat.internal.admin.test', name: 'RocketChat Internal Admin Test', email: 'rocketchat.internal.admin.test@rocket.chat', accessToken: null}; +const channel = {}; +const message = {content: 'Test Message GraphQL', modifiedContent: 'Test Message GraphQL Modified'}; + +const { expect } = require('chai'); + + +describe('GraphQL Tests', function() { + this.retries(0); + + it('Is able to login with username and password', (done) => { + const query = ` + mutation login{ + loginWithPassword(user: {username: "${ user.username }"}, password: "${ user.password }") { + user { + username, + email + }, + tokens { + accessToken + } + } + }`; + request.post('/graphql') + .send({ + query + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('data'); + expect(res.body).to.not.have.property('errors'); + const data = res.body.data.loginWithPassword; + expect(data).to.have.property('user'); + expect(data).to.have.property('tokens'); + user.accessToken = data.tokens.accessToken; + expect(data.user).to.have.property('username', user.username); + expect(data.user).to.have.property('email', user.email); + + }) + .end(done); + }); + it('Is able to login with email and password', (done) => { + const query = ` + mutation login{ + loginWithPassword(user: {email: "${ user.email }"}, password: "${ user.password }") { + user { + username, + email + }, + tokens { + accessToken + } + } + }`; + request.post('/graphql') + .send({ + query + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('data'); + expect(res.body).to.not.have.property('errors'); + const data = res.body.data.loginWithPassword; + expect(data).to.have.property('user'); + expect(data).to.have.property('tokens'); + user.accessToken = data.tokens.accessToken; + expect(data.user).to.have.property('username', user.username); + expect(data.user).to.have.property('email', user.email); + }) + .end(done); + }); + it('Fails when trying to login with wrong password', (done) => { + const query = ` + mutation login{ + loginWithPassword(user: {username: "${ user.username }"}, password: "not!${ user.password }") { + user { + username + }, + tokens { + accessToken + } + } + }`; + request.post('/graphql') + .send({ + query + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('data'); + expect(res.body).to.have.property('errors'); + expect(res.body.data).to.have.property('loginWithPassword', null); + expect(res.body.errors[0]).to.have.property('message', 'Incorrect password'); + }) + .end(done); + }); + + it('Is able to get user data (/me)', (done) => { + const query = ` + { + me { + username, + name, + email, + channels { + id, + name + }, + directMessages { + id, + name + } + } + }`; + request.post('/graphql') + .set('Authorization', user.accessToken) + .send({ + query + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('data'); + expect(res.body).to.not.have.property('errors'); + const me = res.body.data.me; + expect(me).to.have.property('username', user.username); + expect(me).to.have.property('name', user.name); + expect(me).to.have.property('email', user.email); + expect(me.channels).to.be.an('array'); + expect(me.channels[0]).to.have.property('id'); + channel.id = me.channels[0].id; + }) + .end(done); + }); + + it('Is able to send messages to channel', (done) => { + const query = ` + mutation sendMessage{ + sendMessage(channelId: "${ channel.id }", content: "${ message.content }") { + id, + author { + username, + name + }, + content, + channel { + name, + id + }, + reactions { + username, + icon + } + } + }`; + request.post('/graphql') + .set('Authorization', user.accessToken) + .send({ + query + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('data'); + expect(res.body).to.not.have.property('errors'); + const data = res.body.data.sendMessage; + expect(data).to.have.property('id'); + message.id = data.id; + expect(data).to.have.property('author'); + expect(data.author).to.have.property('username', user.username); + expect(data).to.have.property('content', message.content); + expect(data).to.have.property('channel'); + expect(data.channel).to.have.property('id', channel.id); + expect(data).to.have.property('reactions', null); + }) + .end(done); + }); + it('Is able to edit messages', (done) => { + const query = ` + mutation editMessage { + editMessage(id: {messageId: "${ message.id }", channelId: "${ channel.id }"}, content: "${ message.modifiedContent }") { + id, + content, + author { + username + }, + channel { + id, + name + } + } + }`; + request.post('/graphql') + .set('Authorization', user.accessToken) + .send({ + query + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('data'); + expect(res.body).to.not.have.property('errors'); + const data = res.body.data.editMessage; + expect(data).to.have.property('id'); + expect(data).to.have.property('author'); + expect(data.author).to.have.property('username', user.username); + expect(data).to.have.property('content', message.modifiedContent); + expect(data).to.have.property('channel'); + expect(data.channel).to.have.property('id', channel.id); + }) + .end(done); + }); +}); + +/* +subscription chatMessageAdded { + chatMessageAdded(channelId: "Y2EH9PaCy8cw2Ppvm") { + id, + channel { + name + } + } +} + +{ + channels(filter: {joinedChannels: true}) { + name, + id + } +} + +mutation newMessage { + sendMessage(channelId: "Y2EH9PaCy8cw2Ppvm", content: "Testing") { + author { + name + }, + channel { + name + }, + content + } +} + +{ + messages(channelId: "Y2EH9PaCy8cw2Ppvm") { + messagesArray { + id, + author { + name, + id + }, + content, + reactions { + username, + icon + } + } + } +} + +mutation editMessage { + editMessage(id: {messageId: "8yi7ZNpXo2kakcecz", channelId: "Y2EH9PaCy8cw2Ppvm"}, content: "Hi edit") { + author { + name + }, + channel { + name + }, + content + } +} + +mutation login{ + loginWithPassword(user: {username: "gdelavald"}, password: "gdelavald") { + user { + name + }, + tokens { + accessToken + } + } +} + +*/ From 8057275ebc258289f975bb0d8a12baf88c319910 Mon Sep 17 00:00:00 2001 From: Gabriel Delavald Date: Tue, 19 Dec 2017 16:44:51 -0200 Subject: [PATCH 32/42] Adds more tests for graphql api --- tests/end-to-end/graphql/queries.js | 160 +++++++++++++++++----------- 1 file changed, 100 insertions(+), 60 deletions(-) diff --git a/tests/end-to-end/graphql/queries.js b/tests/end-to-end/graphql/queries.js index e348edc8e921..f26bb2b7a2e6 100644 --- a/tests/end-to-end/graphql/queries.js +++ b/tests/end-to-end/graphql/queries.js @@ -15,17 +15,17 @@ describe('GraphQL Tests', function() { it('Is able to login with username and password', (done) => { const query = ` - mutation login{ - loginWithPassword(user: {username: "${ user.username }"}, password: "${ user.password }") { - user { - username, - email - }, - tokens { - accessToken - } + mutation login{ + loginWithPassword(user: {username: "${ user.username }"}, password: "${ user.password }") { + user { + username, + email + }, + tokens { + accessToken } - }`; + } + }`; request.post('/graphql') .send({ query @@ -47,17 +47,18 @@ describe('GraphQL Tests', function() { }); it('Is able to login with email and password', (done) => { const query = ` - mutation login{ - loginWithPassword(user: {email: "${ user.email }"}, password: "${ user.password }") { - user { - username, - email - }, - tokens { - accessToken - } + mutation login{ + loginWithPassword(user: {email: "${ user.email }"}, password: "${ user.password }") { + user { + username, + email, + id + }, + tokens { + accessToken } - }`; + } + }`; request.post('/graphql') .send({ query @@ -78,16 +79,16 @@ describe('GraphQL Tests', function() { }); it('Fails when trying to login with wrong password', (done) => { const query = ` - mutation login{ - loginWithPassword(user: {username: "${ user.username }"}, password: "not!${ user.password }") { - user { - username - }, - tokens { - accessToken - } + mutation login{ + loginWithPassword(user: {username: "${ user.username }"}, password: "not!${ user.password }") { + user { + username + }, + tokens { + accessToken } - }`; + } + }`; request.post('/graphql') .send({ query @@ -105,21 +106,21 @@ describe('GraphQL Tests', function() { it('Is able to get user data (/me)', (done) => { const query = ` - { - me { - username, - name, - email, - channels { - id, - name - }, - directMessages { - id, - name - } + { + me { + username, + name, + email, + channels { + id, + name + }, + directMessages { + id, + name } - }`; + } + }`; request.post('/graphql') .set('Authorization', user.accessToken) .send({ @@ -143,24 +144,24 @@ describe('GraphQL Tests', function() { it('Is able to send messages to channel', (done) => { const query = ` - mutation sendMessage{ - sendMessage(channelId: "${ channel.id }", content: "${ message.content }") { - id, - author { - username, - name - }, - content, - channel { - name, - id - }, - reactions { - username, - icon - } + mutation sendMessage{ + sendMessage(channelId: "${ channel.id }", content: "${ message.content }") { + id, + author { + username, + name + }, + content, + channel { + name, + id + }, + reactions { + username, + icon } - }`; + } + }`; request.post('/graphql') .set('Authorization', user.accessToken) .send({ @@ -218,6 +219,45 @@ describe('GraphQL Tests', function() { }) .end(done); }); + it('Can read messages from channel', (done) => { + const query = ` + { + messages (channelId: "${ channel.id }") { + channel { + id, + name + }, + messagesArray { + id, + author { + username + }, + content + } + } + }`; + request.post('/graphql') + .set('Authorization', user.accessToken) + .send({ + query + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('data'); + expect(res.body).to.not.have.property('errors'); + const data = res.body.data.messages; + expect(data).to.have.property('channel'); + expect(data.channel).to.have.property('id', channel.id); + + expect(data).to.have.property('messagesArray'); + expect(data.messagesArray[0]).to.have.property('id', message.id); + expect(data.messagesArray[0]).to.have.property('author'); + expect(data.messagesArray[0].author).to.have.property('username', user.username); + expect(data.messagesArray[0]).to.have.property('content', message.modifiedContent); + }) + .end(done); + }); }); /* From c694a7afc94e9c58c0c02246ad3d5c605b98dc0c Mon Sep 17 00:00:00 2001 From: Gabriel Delavald Date: Tue, 19 Dec 2017 16:52:30 -0200 Subject: [PATCH 33/42] Fix type on addReactionToMessage method --- .../server/resolvers/messages/addReactionToMessage.js | 2 +- .../server/schemas/messages/addReactionToMessage.graphqls | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-graphql/server/resolvers/messages/addReactionToMessage.js b/packages/rocketchat-graphql/server/resolvers/messages/addReactionToMessage.js index 29a55ded3d95..ee3e49843d52 100644 --- a/packages/rocketchat-graphql/server/resolvers/messages/addReactionToMessage.js +++ b/packages/rocketchat-graphql/server/resolvers/messages/addReactionToMessage.js @@ -6,7 +6,7 @@ import schema from '../../schemas/messages/addReactionToMessage.graphqls'; const resolver = { Mutation: { - addReactionToMassage: authenticated((root, { id, icon }, { user }) => { + addReactionToMessage: authenticated((root, { id, icon }, { user }) => { return new Promise((resolve) => { Meteor.runAsUser(user._id, () => { Meteor.call('setReaction', id.messageId, icon, () => { diff --git a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphqls b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphqls index 61c74c26c499..3b6be025a59b 100644 --- a/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphqls +++ b/packages/rocketchat-graphql/server/schemas/messages/addReactionToMessage.graphqls @@ -1,3 +1,3 @@ type Mutation { - addReactionToMassage(id: MessageIdentifier!, icon: String!): Message + addReactionToMessage(id: MessageIdentifier!, icon: String!): Message } From a487957b3bfbce7b5c3e70ce267e249cb968e852 Mon Sep 17 00:00:00 2001 From: Gabriel Delavald Date: Tue, 26 Dec 2017 13:29:16 -0200 Subject: [PATCH 34/42] Add admin settings for graphql --- packages/rocketchat-graphql/package.js | 2 +- packages/rocketchat-graphql/server/api.js | 26 ++++++++++++++----- .../rocketchat-graphql/server/settings.js | 8 ++++++ 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 packages/rocketchat-graphql/server/settings.js diff --git a/packages/rocketchat-graphql/package.js b/packages/rocketchat-graphql/package.js index 436d212f3e89..e93877ee5814 100644 --- a/packages/rocketchat-graphql/package.js +++ b/packages/rocketchat-graphql/package.js @@ -15,7 +15,7 @@ Package.onUse(function(api) { 'rocketchat:accounts', 'swydo:graphql' ]); - + api.addFiles('server/settings.js', 'server'); api.mainModule('server/api.js', 'server'); }); diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index 1b2177a653d9..32c232eda10d 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -10,15 +10,25 @@ import cors from 'cors'; import { executableSchema } from './schema'; -const subscriptionPort = 3100; +const subscriptionPort = RocketChat.settings.get('Graphql_Subscription_Port') || 3100; // the Meteor GraphQL server is an Express server const graphQLServer = express(); -graphQLServer.use(cors()); +if (RocketChat.settings.get('Graphql_CORS')) { + graphQLServer.use(cors()); +} + +graphQLServer.use(RocketChat.settings.get('Graphql_Endpoint'), (req, res, next) => { + if (RocketChat.settings.get('Graphql_Enabled')) { + next(); + } else { + res.send(400, 'Graphql is not enabled in this server'); + } +}); graphQLServer.use( - '/graphql', + RocketChat.settings.get('Graphql_Endpoint'), bodyParser.json(), graphqlExpress(request => { return { @@ -37,12 +47,12 @@ graphQLServer.use( graphQLServer.use( '/graphiql', graphiqlExpress({ - endpointURL: '/graphql', + endpointURL: RocketChat.settings.get('Graphql_Endpoint'), subscriptionsEndpoint: `ws://localhost:${ subscriptionPort }` }) ); -function startSubscriptionServer() { +const startSubscriptionServer = () => { SubscriptionServer.create({ schema: executableSchema, execute, @@ -55,10 +65,12 @@ function startSubscriptionServer() { }); console.log('GraphQL Subscription server runs on port:', subscriptionPort); -} +}; WebApp.onListening(() => { - startSubscriptionServer(); + if (RocketChat.settings.get('Graphql_Enabled')) { + startSubscriptionServer(); + } }); // this binds the specified paths to the Express server running Apollo + GraphiQL diff --git a/packages/rocketchat-graphql/server/settings.js b/packages/rocketchat-graphql/server/settings.js new file mode 100644 index 000000000000..ce5a177ee9e4 --- /dev/null +++ b/packages/rocketchat-graphql/server/settings.js @@ -0,0 +1,8 @@ +RocketChat.settings.addGroup('General', function() { + this.section('GraphQL API', function() { + this.add('Graphql_Enabled', false, { type: 'boolean', public: false }); + this.add('Graphql_Endpoint', '/graphql', { type: 'string', public: false, enableQuery: { _id: 'Graphql_Enabled', value: true }, Description: 'Requires_restart' }); + this.add('Graphql_CORS', true, { type: 'boolean', public: false, enableQuery: { _id: 'Graphql_Enabled', value: true } }); + this.add('Graphql_Subscription_Port', 3100, { type: 'int', public: false, enableQuery: { _id: 'Graphql_Enabled', value: true } }); + }); +}); From 09e0db46d386ec4ac6d4d838fe3d2c1119745796 Mon Sep 17 00:00:00 2001 From: Gabriel Delavald Date: Sat, 20 Jan 2018 15:18:05 -0200 Subject: [PATCH 35/42] Replace setting endpoint for fixed api url --- packages/rocketchat-graphql/server/api.js | 6 +++--- packages/rocketchat-graphql/server/settings.js | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index 32c232eda10d..d209925ae656 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -19,7 +19,7 @@ if (RocketChat.settings.get('Graphql_CORS')) { graphQLServer.use(cors()); } -graphQLServer.use(RocketChat.settings.get('Graphql_Endpoint'), (req, res, next) => { +graphQLServer.use('/api/graphql', (req, res, next) => { if (RocketChat.settings.get('Graphql_Enabled')) { next(); } else { @@ -28,7 +28,7 @@ graphQLServer.use(RocketChat.settings.get('Graphql_Endpoint'), (req, res, next) }); graphQLServer.use( - RocketChat.settings.get('Graphql_Endpoint'), + '/api/graphql', bodyParser.json(), graphqlExpress(request => { return { @@ -47,7 +47,7 @@ graphQLServer.use( graphQLServer.use( '/graphiql', graphiqlExpress({ - endpointURL: RocketChat.settings.get('Graphql_Endpoint'), + endpointURL: '/api/graphql', subscriptionsEndpoint: `ws://localhost:${ subscriptionPort }` }) ); diff --git a/packages/rocketchat-graphql/server/settings.js b/packages/rocketchat-graphql/server/settings.js index ce5a177ee9e4..f7d06fb80fe4 100644 --- a/packages/rocketchat-graphql/server/settings.js +++ b/packages/rocketchat-graphql/server/settings.js @@ -1,7 +1,6 @@ RocketChat.settings.addGroup('General', function() { this.section('GraphQL API', function() { this.add('Graphql_Enabled', false, { type: 'boolean', public: false }); - this.add('Graphql_Endpoint', '/graphql', { type: 'string', public: false, enableQuery: { _id: 'Graphql_Enabled', value: true }, Description: 'Requires_restart' }); this.add('Graphql_CORS', true, { type: 'boolean', public: false, enableQuery: { _id: 'Graphql_Enabled', value: true } }); this.add('Graphql_Subscription_Port', 3100, { type: 'int', public: false, enableQuery: { _id: 'Graphql_Enabled', value: true } }); }); From edff5c5bd05db13d23642b8c80c6d8b364cb9268 Mon Sep 17 00:00:00 2001 From: Gabriel Delavald Date: Sat, 20 Jan 2018 16:01:44 -0200 Subject: [PATCH 36/42] Change logic for subscription --- packages/rocketchat-graphql/server/api.js | 30 +++++++++++------------ tests/end-to-end/graphql/queries.js | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/rocketchat-graphql/server/api.js b/packages/rocketchat-graphql/server/api.js index d209925ae656..ca1e6d30b8ae 100644 --- a/packages/rocketchat-graphql/server/api.js +++ b/packages/rocketchat-graphql/server/api.js @@ -23,7 +23,7 @@ graphQLServer.use('/api/graphql', (req, res, next) => { if (RocketChat.settings.get('Graphql_Enabled')) { next(); } else { - res.send(400, 'Graphql is not enabled in this server'); + res.status(400).send('Graphql is not enabled in this server'); } }); @@ -53,24 +53,24 @@ graphQLServer.use( ); const startSubscriptionServer = () => { - SubscriptionServer.create({ - schema: executableSchema, - execute, - subscribe, - onConnect: (connectionParams) => ({ authToken: connectionParams.Authorization }) - }, - { - port: subscriptionPort, - host: process.env.BIND_IP || '0.0.0.0' - }); + if (RocketChat.settings.get('Graphql_Enabled')) { + SubscriptionServer.create({ + schema: executableSchema, + execute, + subscribe, + onConnect: (connectionParams) => ({ authToken: connectionParams.Authorization }) + }, + { + port: subscriptionPort, + host: process.env.BIND_IP || '0.0.0.0' + }); - console.log('GraphQL Subscription server runs on port:', subscriptionPort); + console.log('GraphQL Subscription server runs on port:', subscriptionPort); + } }; WebApp.onListening(() => { - if (RocketChat.settings.get('Graphql_Enabled')) { - startSubscriptionServer(); - } + startSubscriptionServer(); }); // this binds the specified paths to the Express server running Apollo + GraphiQL diff --git a/tests/end-to-end/graphql/queries.js b/tests/end-to-end/graphql/queries.js index f26bb2b7a2e6..b1c8bbbb3139 100644 --- a/tests/end-to-end/graphql/queries.js +++ b/tests/end-to-end/graphql/queries.js @@ -262,7 +262,7 @@ describe('GraphQL Tests', function() { /* subscription chatMessageAdded { - chatMessageAdded(channelId: "Y2EH9PaCy8cw2Ppvm") { + chatMessageAdded(channelId: "GENERAL") { id, channel { name From c449bb70579bcbe34f674aac52b122acfa15b36d Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 20 Jan 2018 22:58:56 -0200 Subject: [PATCH 37/42] Fix tests --- tests/end-to-end/graphql/queries.js | 70 ++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/tests/end-to-end/graphql/queries.js b/tests/end-to-end/graphql/queries.js index b1c8bbbb3139..7f429a5e0aee 100644 --- a/tests/end-to-end/graphql/queries.js +++ b/tests/end-to-end/graphql/queries.js @@ -3,16 +3,72 @@ const supertest = require('supertest'); const request = supertest('http://localhost:3000'); +import {adminUsername, adminPassword } from '../../data/user.js'; + const user = {username: 'rocketchat.internal.admin.test', password: 'rocketchat.internal.admin.test', name: 'RocketChat Internal Admin Test', email: 'rocketchat.internal.admin.test@rocket.chat', accessToken: null}; const channel = {}; const message = {content: 'Test Message GraphQL', modifiedContent: 'Test Message GraphQL Modified'}; const { expect } = require('chai'); +const credentials = { + ['X-Auth-Token']: undefined, + ['X-User-Id']: undefined +}; + +const login = { + user: adminUsername, + password: adminPassword +}; describe('GraphQL Tests', function() { this.retries(0); + before((done) => { + request.post('/api/v1/login') + .send(login) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + credentials['X-Auth-Token'] = res.body.data.authToken; + credentials['X-User-Id'] = res.body.data.userId; + }) + .end(done); + }); + + it('should be disabled by default', (done) => { + const query = ` + mutation login{ + loginWithPassword(user: {username: "${ user.username }"}, password: "${ user.password }") { + user { + username, + email + }, + tokens { + accessToken + } + } + }`; + request.post('/api/graphql') + .send({ + query + }) + .expect(400) + .end(done); + }); + + it('should enable GraphQL', (done) => { + request.post('/api/v1/settings/Graphql_Enabled') + .set(credentials) + .send({'value': true}) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + }) + .end(done); + }); + it('Is able to login with username and password', (done) => { const query = ` mutation login{ @@ -26,7 +82,7 @@ describe('GraphQL Tests', function() { } } }`; - request.post('/graphql') + request.post('/api/graphql') .send({ query }) @@ -59,7 +115,7 @@ describe('GraphQL Tests', function() { } } }`; - request.post('/graphql') + request.post('/api/graphql') .send({ query }) @@ -89,7 +145,7 @@ describe('GraphQL Tests', function() { } } }`; - request.post('/graphql') + request.post('/api/graphql') .send({ query }) @@ -121,7 +177,7 @@ describe('GraphQL Tests', function() { } } }`; - request.post('/graphql') + request.post('/api/graphql') .set('Authorization', user.accessToken) .send({ query @@ -162,7 +218,7 @@ describe('GraphQL Tests', function() { } } }`; - request.post('/graphql') + request.post('/api/graphql') .set('Authorization', user.accessToken) .send({ query @@ -199,7 +255,7 @@ describe('GraphQL Tests', function() { } } }`; - request.post('/graphql') + request.post('/api/graphql') .set('Authorization', user.accessToken) .send({ query @@ -236,7 +292,7 @@ describe('GraphQL Tests', function() { } } }`; - request.post('/graphql') + request.post('/api/graphql') .set('Authorization', user.accessToken) .send({ query From 2323ee1e971d6d9cf7754d9295074c2ce174c82f Mon Sep 17 00:00:00 2001 From: Gabriel Delavald Date: Sun, 21 Jan 2018 16:23:46 -0200 Subject: [PATCH 38/42] Add step to disable graphql after testing --- tests/end-to-end/graphql/queries.js | 105 ++++------------------------ 1 file changed, 15 insertions(+), 90 deletions(-) diff --git a/tests/end-to-end/graphql/queries.js b/tests/end-to-end/graphql/queries.js index 7f429a5e0aee..e6c4715e9268 100644 --- a/tests/end-to-end/graphql/queries.js +++ b/tests/end-to-end/graphql/queries.js @@ -3,9 +3,9 @@ const supertest = require('supertest'); const request = supertest('http://localhost:3000'); -import {adminUsername, adminPassword } from '../../data/user.js'; +import {adminUsername, adminPassword, adminEmail} from '../../data/user.js'; -const user = {username: 'rocketchat.internal.admin.test', password: 'rocketchat.internal.admin.test', name: 'RocketChat Internal Admin Test', email: 'rocketchat.internal.admin.test@rocket.chat', accessToken: null}; +const user = {username: adminUsername, password: adminPassword, email: adminEmail, accessToken: null}; const channel = {}; const message = {content: 'Test Message GraphQL', modifiedContent: 'Test Message GraphQL Modified'}; @@ -37,22 +37,7 @@ describe('GraphQL Tests', function() { }); it('should be disabled by default', (done) => { - const query = ` - mutation login{ - loginWithPassword(user: {username: "${ user.username }"}, password: "${ user.password }") { - user { - username, - email - }, - tokens { - accessToken - } - } - }`; - request.post('/api/graphql') - .send({ - query - }) + request.get('/api/graphql') .expect(400) .end(done); }); @@ -189,7 +174,6 @@ describe('GraphQL Tests', function() { expect(res.body).to.not.have.property('errors'); const me = res.body.data.me; expect(me).to.have.property('username', user.username); - expect(me).to.have.property('name', user.name); expect(me).to.have.property('email', user.email); expect(me.channels).to.be.an('array'); expect(me.channels[0]).to.have.property('id'); @@ -314,75 +298,16 @@ describe('GraphQL Tests', function() { }) .end(done); }); -}); - -/* -subscription chatMessageAdded { - chatMessageAdded(channelId: "GENERAL") { - id, - channel { - name - } - } -} - -{ - channels(filter: {joinedChannels: true}) { - name, - id - } -} - -mutation newMessage { - sendMessage(channelId: "Y2EH9PaCy8cw2Ppvm", content: "Testing") { - author { - name - }, - channel { - name - }, - content - } -} - -{ - messages(channelId: "Y2EH9PaCy8cw2Ppvm") { - messagesArray { - id, - author { - name, - id - }, - content, - reactions { - username, - icon - } - } - } -} - -mutation editMessage { - editMessage(id: {messageId: "8yi7ZNpXo2kakcecz", channelId: "Y2EH9PaCy8cw2Ppvm"}, content: "Hi edit") { - author { - name - }, - channel { - name - }, - content - } -} -mutation login{ - loginWithPassword(user: {username: "gdelavald"}, password: "gdelavald") { - user { - name - }, - tokens { - accessToken - } - } -} - -*/ + it('should disable GraphQL', (done) => { + request.post('/api/v1/settings/Graphql_Enabled') + .set(credentials) + .send({'value': false}) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + }) + .end(done); + }); +}); From 381298656d9717d890d4bc6251f540a52aaee135 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Mon, 22 Jan 2018 10:03:22 -0200 Subject: [PATCH 39/42] Improve tests --- tests/end-to-end/graphql/queries.js | 98 +++++++++++++++-------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/tests/end-to-end/graphql/queries.js b/tests/end-to-end/graphql/queries.js index e6c4715e9268..9107e2f435bd 100644 --- a/tests/end-to-end/graphql/queries.js +++ b/tests/end-to-end/graphql/queries.js @@ -36,13 +36,13 @@ describe('GraphQL Tests', function() { .end(done); }); - it('should be disabled by default', (done) => { + before((done) => { request.get('/api/graphql') .expect(400) .end(done); }); - it('should enable GraphQL', (done) => { + before((done) => { request.post('/api/v1/settings/Graphql_Enabled') .set(credentials) .send({'value': true}) @@ -54,19 +54,31 @@ describe('GraphQL Tests', function() { .end(done); }); + after((done) => { + request.post('/api/v1/settings/Graphql_Enabled') + .set(credentials) + .send({'value': false}) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + }) + .end(done); + }); + it('Is able to login with username and password', (done) => { const query = ` - mutation login{ - loginWithPassword(user: {username: "${ user.username }"}, password: "${ user.password }") { - user { - username, + mutation login{ + loginWithPassword(user: {username: "${ user.username }"}, password: "${ user.password }") { + user { + username, email - }, - tokens { - accessToken - } - } - }`; + }, + tokens { + accessToken + } + } + }`; request.post('/api/graphql') .send({ query @@ -86,20 +98,21 @@ describe('GraphQL Tests', function() { }) .end(done); }); + it('Is able to login with email and password', (done) => { const query = ` - mutation login{ - loginWithPassword(user: {email: "${ user.email }"}, password: "${ user.password }") { - user { - username, + mutation login { + loginWithPassword(user: {email: "${ user.email }"}, password: "${ user.password }") { + user { + username, email, id - }, - tokens { - accessToken - } - } - }`; + }, + tokens { + accessToken + } + } + }`; request.post('/api/graphql') .send({ query @@ -118,18 +131,19 @@ describe('GraphQL Tests', function() { }) .end(done); }); + it('Fails when trying to login with wrong password', (done) => { const query = ` - mutation login{ - loginWithPassword(user: {username: "${ user.username }"}, password: "not!${ user.password }") { - user { - username - }, - tokens { - accessToken - } - } - }`; + mutation login { + loginWithPassword(user: {username: "${ user.username }"}, password: "not!${ user.password }") { + user { + username + }, + tokens { + accessToken + } + } + }`; request.post('/api/graphql') .send({ query @@ -184,8 +198,8 @@ describe('GraphQL Tests', function() { it('Is able to send messages to channel', (done) => { const query = ` - mutation sendMessage{ - sendMessage(channelId: "${ channel.id }", content: "${ message.content }") { + mutation sendMessage{ + sendMessage(channelId: "${ channel.id }", content: "${ message.content }") { id, author { username, @@ -201,7 +215,7 @@ describe('GraphQL Tests', function() { icon } } - }`; + }`; request.post('/api/graphql') .set('Authorization', user.accessToken) .send({ @@ -224,6 +238,7 @@ describe('GraphQL Tests', function() { }) .end(done); }); + it('Is able to edit messages', (done) => { const query = ` mutation editMessage { @@ -259,6 +274,7 @@ describe('GraphQL Tests', function() { }) .end(done); }); + it('Can read messages from channel', (done) => { const query = ` { @@ -298,16 +314,4 @@ describe('GraphQL Tests', function() { }) .end(done); }); - - it('should disable GraphQL', (done) => { - request.post('/api/v1/settings/Graphql_Enabled') - .set(credentials) - .send({'value': false}) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res) => { - expect(res.body).to.have.property('success', true); - }) - .end(done); - }); }); From f563bedeb638ea7676e24de6a535a6159ad5ad9d Mon Sep 17 00:00:00 2001 From: Gabriel Delavald Date: Mon, 22 Jan 2018 16:06:28 -0200 Subject: [PATCH 40/42] Fix graphql tests --- .../client/views/pinnedMessages.html | 2 +- tests/end-to-end/api/04-direct-message.js | 8 +++--- .../{graphql/queries.js => api/11-graphql.js} | 27 +++++++++++++++++++ .../end-to-end/ui/04-main-elements-render.js | 21 +++++++++++++++ tests/pageobjects/main-content.page.js | 5 ++-- 5 files changed, 56 insertions(+), 7 deletions(-) rename tests/end-to-end/{graphql/queries.js => api/11-graphql.js} (91%) diff --git a/packages/rocketchat-message-pin/client/views/pinnedMessages.html b/packages/rocketchat-message-pin/client/views/pinnedMessages.html index c3526c43c310..de4e7766165a 100644 --- a/packages/rocketchat-message-pin/client/views/pinnedMessages.html +++ b/packages/rocketchat-message-pin/client/views/pinnedMessages.html @@ -6,7 +6,7 @@

{{_ "No_pinned_messages"}}

{{/unless}} {{/if}} -
+
    {{#each messages}} {{#nrr nrrargs 'message' message}}{{/nrr}} diff --git a/tests/end-to-end/api/04-direct-message.js b/tests/end-to-end/api/04-direct-message.js index 7418f59b96b3..5bf8a8154b48 100644 --- a/tests/end-to-end/api/04-direct-message.js +++ b/tests/end-to-end/api/04-direct-message.js @@ -86,8 +86,8 @@ describe('[Direct Messages]', function() { .end(done); }); - it('/im.close', (done) => { - request.post(api('im.close')) + it('/im.open', (done) => { + request.post(api('im.open')) .set(credentials) .send({ roomId: directMessage._id, @@ -101,8 +101,8 @@ describe('[Direct Messages]', function() { .end(done); }); - it('/im.open', (done) => { - request.post(api('im.open')) + it('/im.close', (done) => { + request.post(api('im.close')) .set(credentials) .send({ roomId: directMessage._id, diff --git a/tests/end-to-end/graphql/queries.js b/tests/end-to-end/api/11-graphql.js similarity index 91% rename from tests/end-to-end/graphql/queries.js rename to tests/end-to-end/api/11-graphql.js index 9107e2f435bd..7b9c28497751 100644 --- a/tests/end-to-end/graphql/queries.js +++ b/tests/end-to-end/api/11-graphql.js @@ -314,4 +314,31 @@ describe('GraphQL Tests', function() { }) .end(done); }); + it('Is able to delete messages', (done) => { + const query = ` + mutation deleteMessage { + deleteMessage(id: {messageId: "${ message.id }", channelId: "${ channel.id }"}) { + id, + author { + username + } + } + }`; + request.post('/api/graphql') + .set('Authorization', user.accessToken) + .send({ + query + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('data'); + expect(res.body).to.not.have.property('errors'); + const data = res.body.data.deleteMessage; + expect(data).to.have.property('id', message.id); + expect(data).to.have.property('author'); + expect(data.author).to.have.property('username', user.username); + }) + .end(done); + }); }); diff --git a/tests/end-to-end/ui/04-main-elements-render.js b/tests/end-to-end/ui/04-main-elements-render.js index 8844506ea5b0..62ffa3ff29f4 100644 --- a/tests/end-to-end/ui/04-main-elements-render.js +++ b/tests/end-to-end/ui/04-main-elements-render.js @@ -287,7 +287,13 @@ describe('[Main Elements Render]', function() { flexTab.operateFlexTab('files', true); }); + after(()=> { + flexTab.moreActions.click(); + flexTab.operateFlexTab('files', false); + }); + it('it should show the files Tab content', () => { + flexTab.filesTabContent.waitForVisible(5000); flexTab.filesTabContent.isVisible().should.be.true; }); }); @@ -298,6 +304,11 @@ describe('[Main Elements Render]', function() { flexTab.operateFlexTab('mentions', true); }); + after(()=> { + flexTab.moreActions.click(); + flexTab.operateFlexTab('mentions', false); + }); + it('it should show the mentions Tab content', () => { flexTab.mentionsTabContent.isVisible().should.be.true; }); @@ -309,6 +320,11 @@ describe('[Main Elements Render]', function() { flexTab.operateFlexTab('starred', true); }); + after(()=> { + flexTab.moreActions.click(); + flexTab.operateFlexTab('starred', false); + }); + it('it should show the starred messages Tab content', () => { flexTab.starredTabContent.isVisible().should.be.true; }); @@ -320,6 +336,11 @@ describe('[Main Elements Render]', function() { flexTab.operateFlexTab('pinned', true); }); + after(()=> { + flexTab.moreActions.click(); + flexTab.operateFlexTab('pinned', false); + }); + it('it should show the pinned messages Tab content', () => { flexTab.pinnedTabContent.isVisible().should.be.true; }); diff --git a/tests/pageobjects/main-content.page.js b/tests/pageobjects/main-content.page.js index 124041fbbf3c..a436d0c07a0e 100644 --- a/tests/pageobjects/main-content.page.js +++ b/tests/pageobjects/main-content.page.js @@ -10,7 +10,7 @@ class MainContent extends Page { get channelTitle() { return browser.element('.rc-header__name'); } //Main Content Footer (Message Input Area) - get messageInput() { return browser.element('.rc-message-box__container textarea'); } + get messageInput() { return browser.element('.js-input-message'); } get sendBtn() { return browser.element('.rc-message-box__icon.js-send'); } get messageBoxActions() { return browser.element('.rc-message-box__icon'); } get recordBtn() { return browser.element('.message-buttons .icon-mic'); } @@ -87,7 +87,8 @@ class MainContent extends Page { // Clear and sets the text to the input setTextToInput(text) { this.messageInput.waitForVisible(5000); - this.messageInput.setValue(text); + this.messageInput.clearElement(); + this.messageInput.addValue(text); } //uploads a file in the given filepath (url). From 3ef5c6917133674dce416e04027cc0ef88196917 Mon Sep 17 00:00:00 2001 From: Gabriel Delavald Date: Mon, 22 Jan 2018 16:09:06 -0200 Subject: [PATCH 41/42] small graphql config changes --- graphql.config.json | 2 +- package.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/graphql.config.json b/graphql.config.json index 2c316a3dbb9f..fbbb30070dde 100644 --- a/graphql.config.json +++ b/graphql.config.json @@ -1,7 +1,7 @@ { "schema": { "request": { - "url" : "http://localhost:3000/graphql", + "url" : "http://localhost:3000/api/graphql", "method" : "POST", "postIntrospectionQuery" : true } diff --git a/package.json b/package.json index 9debebe95a92..0dbf8c3190dc 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,6 @@ "testunit-watch": "mocha --watch --opts ./mocha.opts \"`node -e \"console.log(require('./package.json').mocha.tests.join(' '))\"`\"", "coverage": "nyc -r html mocha --opts ./mocha.opts \"`node -e \"console.log(require('./package.json').mocha.tests.join(' '))\"`\"", "testunit": "mocha --opts ./mocha.opts \"`node -e \"console.log(require('./package.json').mocha.tests.join(' '))\"`\"", - "testgraphql": "mocha --opts ./mocha.opts tests/end-to-end/graphql/*.js", "version": "node .scripts/version.js", "set-version": "node .scripts/set-version.js", "release": "npm run set-version --silent" From 228554866d7304c43cf3ad66aafafea816983594 Mon Sep 17 00:00:00 2001 From: Gabriel Delavald Date: Mon, 22 Jan 2018 16:36:12 -0200 Subject: [PATCH 42/42] Fix broken admin page tests --- tests/pageobjects/administration.page.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/pageobjects/administration.page.js b/tests/pageobjects/administration.page.js index 743bd2887ab9..98bfe5c47789 100644 --- a/tests/pageobjects/administration.page.js +++ b/tests/pageobjects/administration.page.js @@ -65,13 +65,13 @@ class Administration extends Page { //settings get buttonSave() { return browser.element('button.save'); } - get generalButtonExpandIframe() { return browser.element('.section:nth-of-type(2) .button.expand'); } - get generalButtonExpandNotifications() { return browser.element('.section:nth-of-type(3) .button.expand'); } - get generalButtonExpandRest() { return browser.element('.section:nth-of-type(4) .button.expand'); } - get generalButtonExpandReporting() { return browser.element('.section:nth-of-type(5) .button.expand'); } - get generalButtonExpandStreamCast() { return browser.element('.section:nth-of-type(6) .button.expand'); } - get generalButtonExpandTranslations() { return browser.element('.section:nth-of-type(7) .button.expand'); } - get generalButtonExpandUTF8() { return browser.element('.section:nth-of-type(8) .button.expand'); } + get generalButtonExpandIframe() { return browser.element('.section:nth-of-type(3) .button.expand'); } + get generalButtonExpandNotifications() { return browser.element('.section:nth-of-type(4) .button.expand'); } + get generalButtonExpandRest() { return browser.element('.section:nth-of-type(5) .button.expand'); } + get generalButtonExpandReporting() { return browser.element('.section:nth-of-type(6) .button.expand'); } + get generalButtonExpandStreamCast() { return browser.element('.section:nth-of-type(7) .button.expand'); } + get generalButtonExpandTranslations() { return browser.element('.section:nth-of-type(8) .button.expand'); } + get generalButtonExpandUTF8() { return browser.element('.section:nth-of-type(9) .button.expand'); } get generalSiteUrl() { return browser.element('[name="Site_Url"]'); } get generalSiteUrlReset() { return browser.element('.reset-setting[data-setting="Site_Url"]'); } @@ -123,8 +123,8 @@ class Administration extends Page { get generalUTF8NamesSlugReset() { return browser.element('.reset-setting[data-setting="UTF8_Names_Slugify"]'); } //accounts - get accountsButtonExpandDefaultUserPreferences() { return browser.element('.section:nth-of-type(3) .button.expand'); } - get accountsButtonCollapseDefaultUserPreferences() { return browser.element('.section:nth-of-type(3) .button.collapse'); } + get accountsButtonExpandDefaultUserPreferences() { return browser.element('.section:nth-of-type(2) .button.expand'); } + get accountsButtonCollapseDefaultUserPreferences() { return browser.element('.section:nth-of-type(2) .button.collapse'); } get accountsEnableAutoAwayTrue() { return browser.element('label:nth-of-type(1) [name="Accounts_Default_User_Preferences_enableAutoAway"]'); } get accountsEnableAutoAwayFalse() { return browser.element('label:nth-of-type(2) [name="Accounts_Default_User_Preferences_enableAutoAway"]'); }