diff --git a/lib/client.js b/lib/client.js index 4586829e0..f670ef65e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -54,14 +54,13 @@ var OLM_ALGORITHM = "m.olm.v1.curve25519-aes-sha2"; * @param {Object} opts.scheduler Optional. The scheduler to use. If not * specified, this client will not retry requests on failure. This client * will supply its own processing function to + * @param {Object} opts.queryParams Optional. Extra query parameters to append + * to all requests with this client. Useful for application services which require + * ?user_id=. * {@link module:scheduler~MatrixScheduler#setProcessFunction}. */ function MatrixClient(opts) { utils.checkObjectHasKeys(opts, ["baseUrl", "request"]); - utils.checkObjectHasNoAdditionalKeys(opts, [ - "baseUrl", "idBaseUrl", "request", "accessToken", "userId", "store", - "scheduler", "sessionStore", "deviceId" - ]); this.store = opts.store || new StubStore(); this.sessionStore = opts.sessionStore || null; @@ -123,7 +122,8 @@ function MatrixClient(opts) { accessToken: opts.accessToken, request: opts.request, prefix: httpApi.PREFIX_V1, - onlyData: true + onlyData: true, + extraParams: opts.queryParams }; this.credentials = { userId: (opts.userId || null) diff --git a/lib/http-api.js b/lib/http-api.js index d1a90d7f2..bb425c3f2 100644 --- a/lib/http-api.js +++ b/lib/http-api.js @@ -43,6 +43,8 @@ module.exports.PREFIX_IDENTITY_V1 = "/_matrix/identity/api/v1"; * codes and headers in addition to data. Default: false. * @param {string} opts.accessToken The access_token to send with requests. Can be * null to not send an access token. + * @param {Object} opts.extraParams Optional. Extra query parameters to send on + * requests. */ module.exports.MatrixHttpApi = function MatrixHttpApi(opts) { utils.checkObjectHasKeys(opts, ["baseUrl", "request", "prefix"]); @@ -363,6 +365,15 @@ module.exports.MatrixHttpApi.prototype = { "Expected callback to be a function but got " + typeof callback ); } + if (!queryParams) { + queryParams = {}; + } + if (this.opts.extraParams) { + for (var key in this.opts.extraParams) { + if (!this.opts.extraParams.hasOwnProperty(key)) { continue; } + queryParams[key] = this.opts.extraParams[key]; + } + } var defer = q.defer(); this.opts.request( { diff --git a/lib/matrix.js b/lib/matrix.js index 17b9018ec..517613ddc 100644 --- a/lib/matrix.js +++ b/lib/matrix.js @@ -6,7 +6,7 @@ module.exports.MatrixEvent = require("./models/event").MatrixEvent; module.exports.EventStatus = require("./models/event").EventStatus; /** The {@link module:store/memory.MatrixInMemoryStore|MatrixInMemoryStore} class. */ module.exports.MatrixInMemoryStore = require("./store/memory").MatrixInMemoryStore; -/** The {@link module:store/webstorage.WebStorageStore|WebStorageStore} class. */ +/** The {@link module:store/webstorage~WebStorageStore|WebStorageStore} class. */ module.exports.WebStorageStore = require("./store/webstorage"); /** The {@link module:http-api.MatrixHttpApi|MatrixHttpApi} class. */ module.exports.MatrixHttpApi = require("./http-api").MatrixHttpApi; @@ -24,10 +24,10 @@ module.exports.RoomState = require("./models/room-state"); module.exports.User = require("./models/user"); /** The {@link module:scheduler~MatrixScheduler|MatrixScheduler} class. */ module.exports.MatrixScheduler = require("./scheduler"); -/** The {@link module:store/session/webstorage.WebStorageSessionStore| - * ebStorageSessionStore} class */ +/** The {@link module:store/session/webstorage~WebStorageSessionStore| + * WebStorageSessionStore} class */ module.exports.WebStorageSessionStore = require("./store/session/webstorage"); -/** */ +/** True if crypto libraries are being used on this client. */ module.exports.CRYPTO_ENABLED = require("./client").CRYPTO_ENABLED; /** @@ -59,12 +59,15 @@ module.exports.request = function(r) { * @param {(Object|string)} opts The configuration options for this client. If * this is a string, it is assumed to be the base URL. These configuration * options will be passed directly to {@link module:client~MatrixClient}. - * @param {string} opts.baseUrl The base URL to the client-server HTTP API. - * @param {string} opts.accessToken Optional. The access_token for this user. - * @param {string} opts.userId Optional. The user ID for this user. - * @param {Object} opts.store Set to {@link module:store/memory.MatrixInMemoryStore}. - * @param {Object} opts.scheduler Set to {@link module:scheduler~MatrixScheduler}. + * @param {Object} opts.store If not set, defaults to + * {@link module:store/memory.MatrixInMemoryStore}. + * @param {Object} opts.scheduler If not set, defaults to + * {@link module:scheduler~MatrixScheduler}. + * @param {requestFunction} opts.request If not set, defaults to the function + * supplied to {@link request} which defaults to the request module from NPM. * @return {MatrixClient} A new matrix client. + * @see {@link module:client~MatrixClient} for the full list of options for + * opts. */ module.exports.createClient = function(opts) { if (typeof opts === "string") { @@ -72,9 +75,9 @@ module.exports.createClient = function(opts) { "baseUrl": opts }; } - opts.request = request; - opts.store = new module.exports.MatrixInMemoryStore(); - opts.scheduler = new module.exports.MatrixScheduler(); + opts.request = opts.request || request; + opts.store = opts.store || new module.exports.MatrixInMemoryStore(); + opts.scheduler = opts.scheduler || new module.exports.MatrixScheduler(); return new module.exports.MatrixClient(opts); }; diff --git a/lib/pushprocessor.js b/lib/pushprocessor.js index f988f9a4b..fca1e5040 100644 --- a/lib/pushprocessor.js +++ b/lib/pushprocessor.js @@ -1,9 +1,13 @@ +/** + * @module pushprocessor + */ + /** * Construct a Push Processor. * @constructor * @param {Object} client The Matrix client object to use */ -module.exports = function(client) { +function PushProcessor(client) { var escapeRegExp = function(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); }; @@ -237,5 +241,7 @@ module.exports = function(client) { this.actionsForEvent = function(ev) { return pushActionsForEventAndRulesets(ev, client.pushRules); }; -}; +} +/** The PushProcessor class. */ +module.exports = PushProcessor; diff --git a/lib/store/session/webstorage.js b/lib/store/session/webstorage.js index f983d86e2..b0fbd0ced 100644 --- a/lib/store/session/webstorage.js +++ b/lib/store/session/webstorage.js @@ -1,5 +1,9 @@ "use strict"; +/** + * @module store/session/webstorage + */ + var utils = require("../../utils"); var DEBUG = false; // set true to enable console logging.