diff --git a/dist/jmap-client.js b/dist/jmap-client.js new file mode 100644 index 0000000..0d089e3 --- /dev/null +++ b/dist/jmap-client.js @@ -0,0 +1,4729 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jmap = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o + * It exports a single {@link Object} that is exposed as, either: + * * A global `jmap` variable when jmap-client included in a web page through a `script` tag + * * A NodeJS module when jmap-client is `require`'d in a NodeJS application + * + * When extending the library with new models, utility classes, etc. don't forget to update this module + * so that your new code gets exposed in the public API.
+ *
+ * The exported object has the following properties: + * + * @property Client {Client} The {@link Client} class + * @property Utils {Utils} The {@link Utils} class + * @property JSONBuilder {JSONBuilder} The {@link JSONBuilder} class helping to serialize model to json + * @property PromiseProvider {PromiseProvider} The {@link PromiseProvider} class + * @property ES6PromiseProvider { ES6PromiseProvider} The {@link ES6PromiseProvider} class + * @property QPromiseProvider { QPromiseProvider} The {@link QPromiseProvider} class + * @property Transport { Transport} The {@link Transport} class + * @property JQueryTransport { JQueryTransport} The {@link JQueryTransport} class + * @property RequestTransport { RequestTransport} The {@link RequestTransport} class + * @property Model { Model} The {@link Model} class + * @property Account { Account} The {@link Account} class + * @property EMailer { EMailer} The {@link EMailer} class + * @property Mailbox { Mailbox} The {@link Mailbox} class + * @property MessageList { MessageList} The {@link MessageList} class + * @property Message { Message} The {@link Message} class + * @property OutboundMessage {OutboundMessage} The {@link OutboundMessage} class + * @property CreateMessageAck {CreateMessageAck} The {@link CreateMessageAck} class + * @property Thread { Thread} The {@link Thread} class + * @property MailboxRole {MailboxRole} The {@link MailboxRole} class + * @property SetResponse {SetResponse} The {@link SetResponse} class + * @property AuthAccess {AuthAccess} The {@link AuthAccess} class + * @property AuthContinuation {AuthContinuation} The {@link AuthContinuation} class + * @property Constants {Constants} The {@link module:Constants|Constants} object + * @property Attachment {Attachment} The {@link Attachment} class + * @property Capabilities {Capabilities} The {@link Capabilities} class + * @property MailCapabilities {MailCapabilities} The {@link MailCapabilities} class + * @property ServerCapabilities {ServerCapabilities} The {@link ServerCapabilities} class + * @property VacationResponse {VacationResponse} The {@link VacationResponse} class + * @property TransportError {TransportError} The {@link TransportError} class + * @property JmapError {JmapError} The {@link JmapError} class + * + * @module API + */ + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = { + Account: require('./models/Account'), + Attachment: require('./models/Attachment'), + AuthAccess: require('./models/AuthAccess'), + AuthContinuation: require('./models/AuthContinuation'), + AuthMethod: require('./models/AuthMethod'), + Capabilities: require('./models/Capabilities'), + Client: require('./client/Client'), + CreateMessageAck: require('./models/CreateMessageAck'), + Constants: require('./utils/Constants'), + EMailer: require('./models/EMailer'), + ES6PromiseProvider: require('./promises/ES6PromiseProvider'), + FilterRule: require('./models/FilterRule'), + JmapError: require('./errors/JmapError'), + JQueryTransport: require('./transport/JQueryTransport'), + JSONBuilder: require('./utils/JSONBuilder'), + Mailbox: require('./models/Mailbox'), + MailboxRole: require('./models/MailboxRole'), + MailCapabilities: require('./models/MailCapabilities'), + Message: require('./models/Message'), + MessageList: require('./models/MessageList'), + Model: require('./models/Model'), + OutboundMessage: require('./models/OutboundMessage'), + PromiseProvider: require('./promises/PromiseProvider'), + QPromiseProvider: require('./promises/QPromiseProvider'), + RequestTransport: require('./transport/RequestTransport'), + ServerCapabilities: require('./models/ServerCapabilities'), + SetResponse: require('./models/SetResponse'), + Thread: require('./models/Thread'), + Transport: require('./transport/Transport'), + TransportError: require('./errors/TransportError'), + Utils: require('./utils/Utils'), + VacationResponse: require('./models/VacationResponse') +}; +module.exports = exports['default']; + +},{"./client/Client":2,"./errors/JmapError":3,"./errors/TransportError":4,"./models/Account":5,"./models/Attachment":6,"./models/AuthAccess":7,"./models/AuthContinuation":8,"./models/AuthMethod":9,"./models/Capabilities":10,"./models/CreateMessageAck":11,"./models/EMailer":12,"./models/FilterRule":13,"./models/MailCapabilities":14,"./models/Mailbox":15,"./models/MailboxRole":16,"./models/Message":17,"./models/MessageList":18,"./models/Model":19,"./models/OutboundMessage":20,"./models/ServerCapabilities":21,"./models/SetResponse":22,"./models/Thread":23,"./models/VacationResponse":24,"./promises/ES6PromiseProvider":28,"./promises/PromiseProvider":29,"./promises/QPromiseProvider":30,"./transport/JQueryTransport":31,"./transport/RequestTransport":32,"./transport/Transport":33,"./utils/Constants":34,"./utils/JSONBuilder":35,"./utils/Utils":36}],2:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _ES6PromiseProvider = require('./../promises/ES6PromiseProvider.js'); + +var _ES6PromiseProvider2 = _interopRequireDefault(_ES6PromiseProvider); + +var _Utils = require('./../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +var _Account = require('./../models/Account.js'); + +var _Account2 = _interopRequireDefault(_Account); + +var _Mailbox = require('./../models/Mailbox.js'); + +var _Mailbox2 = _interopRequireDefault(_Mailbox); + +var _MessageList = require('./../models/MessageList.js'); + +var _MessageList2 = _interopRequireDefault(_MessageList); + +var _SetResponse = require('./../models/SetResponse.js'); + +var _SetResponse2 = _interopRequireDefault(_SetResponse); + +var _Thread = require('./../models/Thread.js'); + +var _Thread2 = _interopRequireDefault(_Thread); + +var _Message = require('./../models/Message.js'); + +var _Message2 = _interopRequireDefault(_Message); + +var _OutboundMessage = require('./../models/OutboundMessage.js'); + +var _OutboundMessage2 = _interopRequireDefault(_OutboundMessage); + +var _CreateMessageAck = require('./../models/CreateMessageAck.js'); + +var _CreateMessageAck2 = _interopRequireDefault(_CreateMessageAck); + +var _MailboxRole = require('./../models/MailboxRole.js'); + +var _MailboxRole2 = _interopRequireDefault(_MailboxRole); + +var _AuthContinuation = require('./../models/AuthContinuation.js'); + +var _AuthContinuation2 = _interopRequireDefault(_AuthContinuation); + +var _AuthAccess = require('./../models/AuthAccess.js'); + +var _AuthAccess2 = _interopRequireDefault(_AuthAccess); + +var _Constants = require('../utils/Constants.js'); + +var _Constants2 = _interopRequireDefault(_Constants); + +var _VacationResponse = require('./../models/VacationResponse'); + +var _VacationResponse2 = _interopRequireDefault(_VacationResponse); + +var _JmapError = require('../errors/JmapError'); + +var _JmapError2 = _interopRequireDefault(_JmapError); + +var _FilterRule = require('../models/FilterRule'); + +var _FilterRule2 = _interopRequireDefault(_FilterRule); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Client = function () { + /** + * The {@link Client} class is the main entry point for sending JMAP requests to a remote server.
+ * It uses a fluent API so that it's easy to chain calls. JMAP requests are sent using one of the _getXXX_ methods + * that map to their equivalent in the JMAP specification. For instance, if you want to do a _getAccounts_ request, + * you'll use the {@link Client#getAccounts} method. + * + * @param transport {Transport} The {@link Transport} instance used to send HTTP requests. + * @param [promiseProvider={@link ES6PromiseProvider}] {PromiseProvider} The {@link PromiseProvider} implementation to use. + */ + function Client(transport, promiseProvider) { + _classCallCheck(this, Client); + + _Utils2.default.assertRequiredParameterIsPresent(transport, 'transport'); + + this.promiseProvider = promiseProvider || new _ES6PromiseProvider2.default(); + this.transport = transport; + this.transport.promiseProvider = this.promiseProvider; + } + + /** + * Registers an authentication URL, that will be used as the endpoint to send authentication requests to the server.
+ *
+ * The URL will be exposed as the `authenticationUrl` property afterwards. + * + * @param url {String} The authentication url to use in JMAP requests. + * + * @return {Client} This Client instance. + */ + + + _createClass(Client, [{ + key: 'withAuthenticationUrl', + value: function withAuthenticationUrl(url) { + this.authenticationUrl = url; + + return this; + } + + /** + * Registers an authentication token, obtained by an external mechanism from the target JMAP server.
+ * This token will then be used as the `Authorization` header, as per {@link http://jmap.io/spec.html#authenticating-http-requests}.
+ *
+ * The token will be exposed as the `authToken` property afterwards. + * + * @param token {String} The authentication token to use in JMAP requests. + * @param [scheme] {String} The authentication scheme according to RFC 7235 + * + * @return {Client} This Client instance. + */ + + }, { + key: 'withAuthenticationToken', + value: function withAuthenticationToken(token, scheme) { + this.authToken = token; + this.authScheme = scheme; + + return this; + } + + /** + * Sets the API URL of the target JMAP server. All JMAP requests will be sent to this URL.
+ *
+ * The URL will be exposed as the `apiUrl` property afterwards. + * + * @param url {String} The API URL of the JMAP server. + * + * @return {Client} This Client instance. + */ + + }, { + key: 'withAPIUrl', + value: function withAPIUrl(url) { + this.apiUrl = url; + + return this; + } + + /** + * Sets the download URL, i.e.: the URL used to download attachments to {@link Message}s.
+ *
+ * The URL will be exposed as the `downloadUrl` property afterwards. + * + * @param url {String} The download URL of the JMAP server. + * + * @return {Client} This Client instance. + */ + + }, { + key: 'withDownloadUrl', + value: function withDownloadUrl(url) { + this.downloadUrl = url; + + return this; + } + + /** + * Initializes the client with an {@link AuthAccess} model from an authentication response.
+ *
+ * The individual properties of the AuthAccess object will be copied into client properties. + * + * @param access {AuthAccess|Object} The response object from an authenticate process. + * + * @return {Client} This Client instance. + */ + + }, { + key: 'withAuthAccess', + value: function withAuthAccess(access) { + var _this = this; + + _Utils2.default.assertRequiredParameterIsObject(access, 'access'); + + // create an instance of AuthAccess if plain object is given + if (!(access instanceof _AuthAccess2.default)) { + access = new _AuthAccess2.default(this, access); + } + + this.authAccess = access; + this.authScheme = 'X-JMAP'; + this.authToken = access.accessToken; + ['username', 'signingId', 'signingKey', 'apiUrl', 'eventSourceUrl', 'uploadUrl', 'downloadUrl', 'serverCapabilities', 'mailCapabilities'].forEach(function (property) { + _this[property] = access[property]; + }); + + return this; + } + + /** + * Implement the 2-step JMAP authentication protocol.
+ * This method abstract the two authentication steps: + * + * 1. query the JMAP server to get a continuation token + * 2. query the JMAP server with the continuation token (and password), to get the final accessToken. + * + * @param username {String} The username to authenticate with + * @param deviceName {String} A unique device name + * @param continuationCallback {Function} A function that takes an {@link AuthContinuation} + * object as argument, and should return a promise, that will eventually resolve with an + * object denoting the chosen authentication method and the optional password (if method == password). + * + * @return {Promise} A {@link Promise} that will eventually be resovled with a {@link AuthAccess} object + */ + + }, { + key: 'authenticate', + value: function authenticate(username, deviceName, continuationCallback) { + var _this2 = this; + + return this.transport.post(this.authenticationUrl, this._defaultNonAuthenticatedHeaders(), { + username: username, + deviceName: deviceName, + clientName: _Constants2.default.CLIENT_NAME, + clientVersion: _Constants2.default.VERSION + }).then(function (data) { + return _this2._authenticateResponse(data, continuationCallback); + }); + } + + /** + * Sub-routine handling JMAP server responses on authentication requests + * + * Depending on the server's response, this either (recursively) executes the second + * authentication step by calling the provided continuationCallback or resolves on + * successfully completed authentication. + * + * @param data {Object} The JMAP response data + * @param continuationCallback {Function} The callback function initially passed to the authenticate() method + * + * @return {Promise} A {@link Promise} that will eventually be resovled with a {@link AuthAccess} object + */ + + }, { + key: '_authenticateResponse', + value: function _authenticateResponse(data, continuationCallback) { + var _this3 = this; + + if (data.loginId && data.accessToken === undefined) { + // got an AuthContinuation response + var authContinuation = new _AuthContinuation2.default(data); + + return continuationCallback(authContinuation).then(function (continueData) { + if (!authContinuation.supports(continueData.type)) { + throw new Error('The "' + continueData.type + '" authentication type is not supported by the server.'); + } + var param = { + loginId: authContinuation.loginId, + type: continueData.type + }; + + if (continueData.value) { + param.value = continueData.value; + } + + return _this3.transport.post(_this3.authenticationUrl, _this3._defaultNonAuthenticatedHeaders(), param); + }).then(function (resp) { + return _this3._authenticateResponse(resp, continuationCallback); + }); + } else if (data.accessToken && data.loginId === undefined) { + // got auth access response + return new _AuthAccess2.default(this, data); + } else { + // got unknown response data + throw new Error('Unexpected response on authorization request'); + } + } + + /** + * Implement the JMAP external authentication protocol.
+ * This method abstract the two authentication steps: + * + * 1. query the JMAP server to get a continuation token + * 2. query the JMAP server with the continuation token, to get the final accessToken. + * + *
+ * Between those two steps, a user provided function wil be called to handle the external + * authentication part. + *
+ * This method returns a promise that will eventually be resovled with a {@link AuthAccess} object. + * It's the responsability of the caller to then set the AuthToken using for example: + *
+ * + * client.withAuthenticationToken(authAccess.accessToken); + * + * @param username {String} The username of the user to authenticate. + * @param deviceName {String} A unique device name + * @param continuationCallback {Function} A function that takes an {@link AuthContinuation} object as argument, and should return a promise, that will resolve once the external authentication is complete. + * + * @return {Promise} A {@link Promise} that will eventually be resovled with a {@link AuthAccess} object + */ + + }, { + key: 'authExternal', + value: function authExternal(username, deviceName, continuationCallback) { + return this.authenticate(username, deviceName, function (authContinuation) { + // wrap the continuationCallback to resolve with method:'external' + return continuationCallback(authContinuation).then(function () { + return { type: 'external' }; + }); + }); + } + + /** + * Implement the JMAP password authentication protocol.
+ * This method abstract the two authentication steps: + * + * 1. query the JMAP server to get a continuation token + * 2. query the JMAP server with the continuation token and the password, to get the final accessToken. + * + * @param username {String} The username of the user to authenticate + * @param password {String} The password of the user to authenticate + * @param deviceName {String} A unique device name + * + * @return {Promise} A {@link Promise} that will eventually be resovled with a {@link AuthAccess} object + */ + + }, { + key: 'authPassword', + value: function authPassword(username, password, deviceName) { + return this.authenticate(username, deviceName, function () { + return this.promiseProvider.newPromise(function (resolve, reject) { + resolve({ type: 'password', value: password }); + }); + }.bind(this)); + } + + /** + * Sends a _getAccounts_ JMAP request. + * + * @param [options=null] {Object} The options to the _getAccounts_ JMAP request. + * + * @return {Promise} A {@link Promise} that eventually resolves to an array of {@link Account} objects. + * + * @see http://jmap.io/spec.html#getaccounts + */ + + }, { + key: 'getAccounts', + value: function getAccounts(options) { + // resolve with accounts list from AuthAccess + if (this.authAccess instanceof _AuthAccess2.default) { + return this.promiseProvider.newPromise(function (resolve, reject) { + var accounts = []; + + // equivalent to Object.values() + for (var id in this.authAccess.accounts) { + if (this.authAccess.accounts.hasOwnProperty(id)) { + accounts.push(this.authAccess.accounts[id]); + } + } + + resolve(accounts); + }.bind(this)); + } + + // fallback to deprecated getAccounts request + return this._jmapRequest('getAccounts', options); + } + + /** + * Sends a _getMailboxes_ JMAP request. + * + * @param [options=null] {Object} The options to the _getMailboxes_ JMAP request. + * + * @return {Promise} A {@link Promise} that eventually resolves to an array of {@link Mailbox} objects. + * + * @see http://jmap.io/spec.html#getmailboxes + */ + + }, { + key: 'getMailboxes', + value: function getMailboxes(options) { + return this._jmapRequest('getMailboxes', options); + } + + /** + * Sends a _setMailboxes_ JMAP request. + * + * @param [options=null] {Object} The options to the _setMailboxes_ JMAP request. + * + * @return {Promise} A {@link Promise} that eventually resolves to a {@link Mailbox} object. + * + * @see http://jmap.io/spec.html#setmailboxes + */ + + }, { + key: 'setMailboxes', + value: function setMailboxes(options) { + return this._jmapRequest('setMailboxes', options); + } + + /** + * Creates a mailbox by sending a _setMailboxes_ JMAP request.
+ * + * @param name {String} The name of the mailbox to create. + * @param [parentId=null] {String} The id of the parent of the mailbox to create. + * + * @return {Promise} A {@link Promise} that eventually resolves to a {@link Mailbox}. + * + * @see http://jmap.io/spec.html#creating-mailboxes + */ + + }, { + key: 'createMailbox', + value: function createMailbox(name, parentId) { + var _this4 = this; + + _Utils2.default.assertRequiredParameterIsPresent(name, 'name'); + + var clientId = this._generateClientId(); + + return this.setMailboxes({ + create: _defineProperty({}, clientId, { + name: name, + parentId: parentId + }) + }).then(function (response) { + var created = response.created[clientId]; + + if (!created) { + throw new Error('Failed to create mailbox, clientId: ' + clientId + ', message: ' + (response.notCreated[clientId] || 'none')); + } + + return new _Mailbox2.default(_this4, created.id, created.name || name, created); + }); + } + + /** + * Updates properties of a {@link Mailbox}.
+ * This will issue a {@link Client#setMailboxes} JMAP request under the hoods, passing the correct options. + * + * @param id {String} The id of the {@link Mailbox} to update. + * @param options {Object} The options of the target mailbox to be updated. + * + * @return {Promise} A {@link Promise} that eventually resolves to nothing if the mailbox was updated successfully. + * + * @see http://jmap.io/spec.html#updating-mailboxes + */ + + }, { + key: 'updateMailbox', + value: function updateMailbox(id, options) { + _Utils2.default.assertRequiredParameterIsPresent(id, 'id'); + + return this.setMailboxes({ + update: _defineProperty({}, id, options) + }).then(function (response) { + if (response.updated.indexOf(id) < 0) { + throw new Error('Failed to update mailbox ' + id + ', the reason is: ' + response.notUpdated[id]); + } + }); + } + + /** + * Destroy the {@link Mailbox} related to the given _id_ on the server.
+ * This will issue a {@link Client#destroyMailboxes} request under the hoods, passing _[id]_ option. + * + * @param id {String} The id of the mailbox to destroy. + * + * @return {Promise} A {@link Promise} that eventually resolves to nothing if the {@link Mailbox} was destroyed successfully. + * + */ + + }, { + key: 'destroyMailbox', + value: function destroyMailbox(id) { + _Utils2.default.assertRequiredParameterIsPresent(id, 'id'); + + return this.destroyMailboxes([id]); + } + + /** + * Destroy multiple {@link Mailbox}es specified to the given _ids_ on the server.
+ * This will issue a {@link Client#setMailboxes} JMAP request under the hoods, passing the correct options. + * + * @param ids {String[]} An array IDs of the mailboxes to destroy. These IDs must be in the right order: Destroy X comes before destroy Y if X is a descendent of Y. + * + * @return {Promise} A {@link Promise} that eventually resolves to nothing if all {@link Mailbox}es were destroyed successfully. Otherwise, it rejects error message of the first `notDestroyed` mailbox. + * + * @see http://jmap.io/spec.html#destroying-mailboxes + */ + + }, { + key: 'destroyMailboxes', + value: function destroyMailboxes(ids) { + _Utils2.default.assertRequiredParameterIsArrayWithMinimumLength(ids, 'ids', 1); + + return this.setMailboxes({ + destroy: ids + }).then(function (response) { + var notDestroyedIds = Object.keys(response.notDestroyed); + + if (notDestroyedIds.length > 0) { + // take the first one for incrementally debugging + var setError = response.notDestroyed[notDestroyedIds[0]]; + var reason = setError.type + ' (' + setError.description + ')'; + + throw new Error('Failed to destroy ' + notDestroyedIds[0] + ', the reason is: ' + reason); + } + }); + } + + /** + * Finds a {@link Mailbox} with the given role.
+ * This will issue a _getMailboxes_ JMAP request and search for the mailbox in the returned list. + * + * @param role {MailboxRole|String} The desired mailbox role. + * @param [options=null] {Object} The options to the implicit _getMailboxes_ JMAP request. + * + * @return {Promise} A {@link Promise} that eventually resolves to the {@link Mailbox} if found. + * + * @see MailboxRole + */ + + }, { + key: 'getMailboxWithRole', + value: function getMailboxWithRole(role, options) { + if (!(role instanceof _MailboxRole2.default)) { + role = _MailboxRole2.default.fromRole(role); + } + + if (role === _MailboxRole2.default.UNKNOWN) { + throw new Error('A valid role is required to find a mailbox by role'); + } + + return this._jmapRequest('getMailboxes', options).then(function (mailboxes) { + for (var i = 0; i < mailboxes.length; i++) { + if (mailboxes[i].role === role) { + return mailboxes[i]; + } + } + + throw new Error('Cannot find a mailbox with role ' + role.value); + }); + } + + /** + * Sends a _getMessageList_ JMAP request. + * + * @param [options=null] {Object} The options to the _getMessageList_ JMAP request. + * + * @return {Promise} A {@link Promise} that eventually resolves to a {@link MessageList} object. + * + * @see http://jmap.io/spec.html#getmessagelist + */ + + }, { + key: 'getMessageList', + value: function getMessageList(options) { + return this._jmapRequest('getMessageList', options); + } + + /** + * Sends a _getThreads_ JMAP request. + * + * @param [options=null] {Object} The options to the _getThreads_ JMAP request. + * + * @return {Promise} A {@link Promise} that eventually resolves to an array of {@link Thread} objects. + * + * @see http://jmap.io/spec.html#getthreads + */ + + }, { + key: 'getThreads', + value: function getThreads(options) { + return this._jmapRequest('getThreads', options); + } + + /** + * Sends a _getMessages_ JMAP request. + * + * @param [options=null] {Object} The options to the _getMessages_ JMAP request. + * + * @return {Promise} A {@link Promise} that eventually resolves to an array of {@link Message} objects. + * + * @see http://jmap.io/spec.html#getmessages + */ + + }, { + key: 'getMessages', + value: function getMessages(options) { + return this._jmapRequest('getMessages', options); + } + + /** + * Sends a _setMessages_ JMAP request. + * + * @param [options=null] {Object} The options to the _setMessages_ JMAP request. + * + * @return {Promise} A {@link Promise} that eventually resolves to a {@link SetResponse} object. + * + * @see http://jmap.io/spec.html#setmessages + */ + + }, { + key: 'setMessages', + value: function setMessages(options) { + return this._jmapRequest('setMessages', options); + } + + /** + * Updates properties of a {@link Message}.
+ * This will issue a {@link Client#setMessages} JMAP request under the hoods, passing the correct options. + * + * @param id {String} The id of the {@link Message} to update. + * @param options {Object} The options of the target message to be updated. + * @param options.mailboxIds {String[]} The identifiers of the new mailboxes for the message. + * @param options.isFlagged {Boolean} This corresponds whether the message is flagged or not + * @param options.isUnread {Boolean} This corresponds whether the message has been yet read or not + * @param options.isAnswered {Boolean} This corresponds whether the message has been yet replied or not + * + * @return {Promise} A {@link Promise} that eventually resolves to nothing if the message was updated successfully. + * + * @see http://jmap.io/spec.html#updating-messages + */ + + }, { + key: 'updateMessage', + value: function updateMessage(id, options) { + _Utils2.default.assertRequiredParameterIsPresent(id, 'id'); + _Utils2.default.assertRequiredParameterIsObject(options, 'options'); + + return this.setMessages({ + update: _defineProperty({}, id, options) + }).then(function (response) { + if (response.updated.indexOf(id) < 0) { + throw new Error('Failed to update message ' + id + ', the reason is: ' + (response.notUpdated[id] || 'missing')); + } + }); + } + + /** + * Destroy the {@link Message} related to the given _id_ on the server.
+ * This will issue a {@link Client#setMessages} JMAP request under the hoods, passing the correct options. + * + * @param id {String} The id of the object to destroy. + * + * @return {Promise} A {@link Promise} that eventually resolves to nothing if the {@link Message} was destroyed successfully. + * + * @see Client#setMessages + */ + + }, { + key: 'destroyMessage', + value: function destroyMessage(id) { + return this.destroyMessages(id && [id]).then(function (response) { + if (response.destroyed.indexOf(id) < 0) { + throw new Error('Failed to destroy ' + id + ', the reason is: ' + (response.notDestroyed[id] || 'missing')); + } + }); + } + + /** + * Destroy several {@link Message}s at once.
+ * This will issue a {@link Client#setMessages} JMAP request under the hoods, passing the correct options. + * + * @param ids {String[]} The list of ids of the messages to destroy. + * + * @return {Promise} A {@link Promise} that resolves to a {@link SetResponse}, containing the result of the operation. + * + * @see Client#setMessages + */ + + }, { + key: 'destroyMessages', + value: function destroyMessages(ids) { + _Utils2.default.assertRequiredParameterIsArrayWithMinimumLength(ids, 'ids', 1); + + return this.setMessages({ destroy: ids }); + } + + /** + * Save a message as draft by sending a _setMessages_ JMAP request.
+ * The _mailboxIds_ and _isDraft_ properties of the given _message_ will be overridden by this method. + * + * @param message {OutboundMessage} The message to save. + * + * @return {Promise} A {@link Promise} that eventually resolves to a {@link CreateMessageAck}. + * + * @see http://jmap.io/spec.html#saving-a-draft + */ + + }, { + key: 'saveAsDraft', + value: function saveAsDraft(message) { + return this._createMessage(message, _MailboxRole2.default.DRAFTS); + } + + /** + * Sends a message by issuing a _setMessages_ JMAP request.
+ * The _mailboxIds_ and _isDraft_ properties of the given _message_ will be overridden by this method. + * + * @param message {OutboundMessage} The message to send. + * @param outbox {Mailbox} The {@link Mailbox} with role='outbox', if already available + * + * @return {Promise} A {@link Promise} that eventually resolves to a {@link CreateMessageAck}. + * + * @see http://jmap.io/spec.html#sending-messages + */ + + }, { + key: 'send', + value: function send(message, outbox) { + return this._createMessage(message, _MailboxRole2.default.OUTBOX, outbox); + } + + /** + * Moves a {@link Message} to a different set of mailboxes.
+ * This will issue a {@link Client#setMessages} JMAP request under the hoods, passing the correct options. + * + * @param id {String} The id of the {@link Message} to move. + * @param mailboxIds {String[]} The identifiers of the target mailboxes for the message. + * + * @return {Promise} A {@link Promise} that eventually resolves to nothing if the message was moved successfully. + * + * @see Client#setMessages + */ + + }, { + key: 'moveMessage', + value: function moveMessage(id, mailboxIds) { + _Utils2.default.assertRequiredParameterIsPresent(id, 'id'); + _Utils2.default.assertRequiredParameterIsArrayWithMinimumLength(mailboxIds, 'mailboxIds', 1); + + return this.updateMessage(id, { mailboxIds: mailboxIds }); + } + + /** + * Gets the singleton {@link VacationResponse} instance for a given account.
+ * This will send a `getVacationResponse` request to the JMAP backend. + * + * @param [options] {Object} The options to the underlying `getVacationResponse` JMAP request. + * @param [options.accountId=null] {String} The account ID to get the vacation response for. If `null`, the primary account is used. + * + * @returns {Promise} A {@link Promise} that eventually resolves to the {@link VacationResponse} instance. + */ + + }, { + key: 'getVacationResponse', + value: function getVacationResponse(options) { + return this._jmapRequest('getVacationResponse', options).then(function (list) { + return list[0]; + }); + } + + /** + * Sets the singleton {@link VacationResponse} instance for a given account.
+ * This will send a `setVacationResponse` request to the JMAP backend. + * + * @param vacationResponse {VacationResponse} The {@link VacationResponse} instance to set + * @param [options] {Object} The options to the underlying `setVacationResponse` JMAP request. + * @param [options.accountId=null] {String} The account ID to set the vacation response for. If `null`, the primary account is used. + * + * @returns {Promise} A {@link Promise} that eventually resolves to nothing upon success. + */ + + }, { + key: 'setVacationResponse', + value: function setVacationResponse(vacationResponse, options) { + _Utils2.default.assertRequiredParameterHasType(vacationResponse, 'vacationResponse', _VacationResponse2.default); + + return this._jmapRequest('setVacationResponse', { + accountId: options && options.accountId, + update: _defineProperty({}, _VacationResponse2.default.ID, vacationResponse.toJSONObject()) + }).then(function (response) { + if (response.updated.indexOf(_VacationResponse2.default.ID) < 0) { + throw new Error('Failed to set vacation response. Error: ' + (response.notUpdated[_VacationResponse2.default.ID] || 'none')); + } + }); + } + }, { + key: '_createMessage', + value: function _createMessage(message, role, mailbox) { + var _this5 = this; + + _Utils2.default.assertRequiredParameterHasType(message, 'message', _OutboundMessage2.default); + + var clientId = this._generateClientId(), + doSetMessages = function doSetMessages(mailbox) { + message.mailboxIds = [mailbox.id]; + message.isDraft = _MailboxRole2.default.DRAFTS.value === role.value ? true : null; + + return _this5.setMessages({ + create: _defineProperty({}, clientId, message.toJSONObject()) + }).then(function (response) { + if (!response.created[clientId]) { + throw new Error('Failed to store message with clientId ' + clientId + '. Error: ' + (response.notCreated[clientId] || 'none')); + } + + return new _CreateMessageAck2.default(_this5, response.created[clientId]); + }); + }; + + return mailbox ? doSetMessages(mailbox) : this.getMailboxWithRole(role).then(doSetMessages); + } + }, { + key: '_generateClientId', + value: function _generateClientId() { + return Date.now(); + } + + /** + * Sets the singleton {@link FilterRule} instance for a given account.
+ * This will send a `setFilter` request to the JMAP backend. + * + * @param filterRules {FilterRule[]|Object[]} The list of filter rules to set + * @param [options] {Object} The options to the underlying `setFilter` JMAP request. + * @param [options.accountId=null] {String} The account ID to set the filtering rules for. If `null`, the primary account is used. + * + * @returns {Promise} A {@link Promise} that eventually resolves to nothing upon success. + */ + + }, { + key: 'setFilter', + value: function setFilter(filterRules, options) { + var filterRulesAsJson = filterRules.map(function (rule) { + return rule instanceof _FilterRule2.default ? rule.toJSONObject() : rule; + }); + + return this._jmapRequest('setFilter', _defineProperty({ + accountId: options && options.accountId, + ifInState: options && options.ifInState || null + }, _FilterRule2.default.ID, filterRulesAsJson)).then(function (response) { + if (response.updated.indexOf(_FilterRule2.default.ID) < 0) { + throw new Error('Failed to set filter. Error: ' + (response.notUpdated[_FilterRule2.default.ID] || 'none')); + } + }); + } + }, { + key: 'getFilter', + value: function getFilter(options) { + return this._jmapRequest('getFilter', options).then(function (response) { + return response.singleton; + }); + } + }, { + key: '_defaultNonAuthenticatedHeaders', + value: function _defaultNonAuthenticatedHeaders() { + return { + Accept: 'application/json; charset=UTF-8', + 'Content-Type': 'application/json; charset=UTF-8' + }; + } + }, { + key: '_defaultHeaders', + value: function _defaultHeaders() { + return { + Accept: 'application/json; charset=UTF-8', + 'Content-Type': 'application/json; charset=UTF-8', + Authorization: (this.authScheme ? this.authScheme + ' ' : '') + this.authToken + }; + } + }, { + key: '_jmapRequest', + value: function _jmapRequest(method, options) { + var _this6 = this; + + return this.transport.post(this.apiUrl, this._defaultHeaders(), [[method, options || {}, '#0']]).then(function (data) { + return _Utils2.default.assertValidJMAPResponse(method, data); + }).then(function (data) { + return data.map(function (response) { + return _this6._handleResponse(response, method); + }); + }).then(function (responses) { + return responses.length > 1 ? responses : responses[0]; + }); + } + }, { + key: '_handleResponse', + value: function _handleResponse(response, method) { + var name = response[0], + fn = this['_handle' + _Utils2.default.capitalize(name) + 'Response']; + + // This will return the "raw" data if the command is unknown to the client + return fn ? fn.bind(this)(response, method) : response[1]; + } + }, { + key: '_handleErrorResponse', + value: function _handleErrorResponse(response, method) { + throw new _JmapError2.default(response[1], method); + } + }, { + key: '_handleListResponse', + value: function _handleListResponse(response, Model, filter) { + return _Utils2.default._jsonArrayToModelList(this, Model, response[1].list, filter); + } + }, { + key: '_handleSetResponse', + value: function _handleSetResponse(response) { + return _SetResponse2.default.fromJSONObject(this, response[1]); + } + }, { + key: '_handleAccountsResponse', + value: function _handleAccountsResponse(response) { + return this._handleListResponse(response, _Account2.default); + } + }, { + key: '_handleThreadsResponse', + value: function _handleThreadsResponse(response) { + return this._handleListResponse(response, _Thread2.default); + } + }, { + key: '_handleMessagesResponse', + value: function _handleMessagesResponse(response) { + return this._handleListResponse(response, _Message2.default, function (message) { + try { + return _Utils2.default.assertRequiredParameterIsArrayWithMinimumLength(message.mailboxIds, 'mailboxIds', 1); + } catch (err) { + return false; + } + }); + } + }, { + key: '_handleMailboxesResponse', + value: function _handleMailboxesResponse(response) { + return this._handleListResponse(response, _Mailbox2.default); + } + }, { + key: '_handleMailboxesSetResponse', + value: function _handleMailboxesSetResponse(response) { + return this._handleSetResponse(response); + } + }, { + key: '_handleMessageListResponse', + value: function _handleMessageListResponse(response) { + return _MessageList2.default.fromJSONObject(this, response[1]); + } + }, { + key: '_handleMessagesSetResponse', + value: function _handleMessagesSetResponse(response) { + return this._handleSetResponse(response); + } + }, { + key: '_handleVacationResponseResponse', + value: function _handleVacationResponseResponse(response) { + return this._handleListResponse(response, _VacationResponse2.default); + } + }, { + key: '_handleVacationResponseSetResponse', + value: function _handleVacationResponseSetResponse(response) { + return this._handleSetResponse(response); + } + }]); + + return Client; +}(); + +exports.default = Client; +module.exports = exports['default']; + +},{"../errors/JmapError":3,"../models/FilterRule":13,"../utils/Constants.js":34,"./../models/Account.js":5,"./../models/AuthAccess.js":7,"./../models/AuthContinuation.js":8,"./../models/CreateMessageAck.js":11,"./../models/Mailbox.js":15,"./../models/MailboxRole.js":16,"./../models/Message.js":17,"./../models/MessageList.js":18,"./../models/OutboundMessage.js":20,"./../models/SetResponse.js":22,"./../models/Thread.js":23,"./../models/VacationResponse":24,"./../promises/ES6PromiseProvider.js":28,"./../utils/Utils.js":36}],3:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Utils = require('../utils/Utils'); + +var _Utils2 = _interopRequireDefault(_Utils); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +function _extendableBuiltin(cls) { + function ExtendableBuiltin() { + cls.apply(this, arguments); + } + + ExtendableBuiltin.prototype = Object.create(cls.prototype, { + constructor: { + value: cls, + enumerable: false, + writable: true, + configurable: true + } + }); + + if (Object.setPrototypeOf) { + Object.setPrototypeOf(ExtendableBuiltin, cls); + } else { + ExtendableBuiltin.__proto__ = cls; + } + + return ExtendableBuiltin; +} + +var JmapError = function (_extendableBuiltin2) { + _inherits(JmapError, _extendableBuiltin2); + + /** + * A `JmapError` is a custom `Error` thrown when a request is rejected by the JMAP backend.
+ * The _type_ property holds the type of error that happened. Refer to the JMAP [spec](http://jmap.io/spec-core.html#errors) + * for details on the available errors.
+ * Other properties may be present with further information; these are detailed in the method descriptions where appropriate. + * + * @constructor + * + * @param payload {Object} The error payload, from which detailed information about the error can be retrieved. + * @param [payload.type] {String} The type of this `JmapError`. + * @param [payload.description=null] {String} The description, if any, of this `JmapError`. + * @param [method=null] {String} The JMAP method that triggered this `JmapError`. + * + * @see Error + */ + function JmapError(payload, method) { + _classCallCheck(this, JmapError); + + var _this = _possibleConstructorReturn(this, (JmapError.__proto__ || Object.getPrototypeOf(JmapError)).call(this)); + + _Utils2.default.assertRequiredParameterIsPresent(payload, 'payload'); + _Utils2.default.assertRequiredParameterIsPresent(payload.type, 'payload.type'); + + _this.payload = payload; + _this.type = payload.type; + _this.description = payload.description || null; + + _this.method = method || null; + return _this; + } + + /** + * Returns a {@link String} representation of this `JmapError`. + * + * @returns {String} The human-readable representation of this `JmapError`. + */ + + + _createClass(JmapError, [{ + key: 'toString', + value: function toString() { + return 'JmapError{type=' + this.type + ',description=' + this.description + ',method=' + this.method + '}'; + } + }]); + + return JmapError; +}(_extendableBuiltin(Error)); + +exports.default = JmapError; +module.exports = exports['default']; + +},{"../utils/Utils":36}],4:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +function _extendableBuiltin(cls) { + function ExtendableBuiltin() { + cls.apply(this, arguments); + } + + ExtendableBuiltin.prototype = Object.create(cls.prototype, { + constructor: { + value: cls, + enumerable: false, + writable: true, + configurable: true + } + }); + + if (Object.setPrototypeOf) { + Object.setPrototypeOf(ExtendableBuiltin, cls); + } else { + ExtendableBuiltin.__proto__ = cls; + } + + return ExtendableBuiltin; +} + +var TransportError = function (_extendableBuiltin2) { + _inherits(TransportError, _extendableBuiltin2); + + /** + * A `TransportError` is a custom `Error` thrown when a request to a remote server fails. + * + * @constructor + * + * @param [cause=null] {*} The underlying cause of this `TransportError`. Though this is usually an {@link Error}, this + * might actually be anything and depends on the chosen {@link Transport} implementation. + * @param [statusCode=0] {Number} The HTTP status code sent by the server, if the request reached the server. + * @param [responseText=null] {String} The HTTP response sent by the server, if any. + * + * @see Transport + * @see Error + */ + function TransportError(cause, statusCode, responseText) { + _classCallCheck(this, TransportError); + + var _this = _possibleConstructorReturn(this, (TransportError.__proto__ || Object.getPrototypeOf(TransportError)).call(this)); + + _this.cause = cause || null; + _this.statusCode = statusCode || 0; + _this.responseText = responseText || null; + return _this; + } + + return TransportError; +}(_extendableBuiltin(Error)); + +exports.default = TransportError; +module.exports = exports['default']; + +},{}],5:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +var _JSONBuilder = require('../utils/JSONBuilder.js'); + +var _JSONBuilder2 = _interopRequireDefault(_JSONBuilder); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Account = function (_Model) { + _inherits(Account, _Model); + + /** + * This class represents a JMAP [Account]{@link http://jmap.io/spec.html#accounts}. + * + * @constructor + * @extends Model + * + * @param jmap {Client} The {@link Client} instance that created this _Account_. + * @param id {String} The unique identifier of this _Account_. + * @param [opts] {Object} The optional properties of this _Account_. + * @param [opts.name=''] {String} The name of this _Account_. + * @param [opts.isPrimary=false] {Boolean} Whether this _Account_ is the primary email account. + * @param [opts.isReadOnly=false] {Boolean} Whether the entire _Account_ is read-only + * @param [opts.hasDataFor=[]] {String[]} A list of the data profiles available in this account + server. + * + * @see Model + */ + function Account(jmap, id, opts) { + _classCallCheck(this, Account); + + var _this = _possibleConstructorReturn(this, (Account.__proto__ || Object.getPrototypeOf(Account)).call(this, jmap)); + + _Utils2.default.assertRequiredParameterIsPresent(id, 'id'); + + opts = opts || {}; + + _this.id = id; + _this.name = opts.name || ''; + _this.isPrimary = opts.isPrimary || false; + _this.isReadOnly = opts.isReadOnly || false; + _this.hasDataFor = opts.hasDataFor || []; + return _this; + } + + /** + * Returns whether this `Account` supports mail or not. + * + * @returns {Boolean} _true_ if and only if this `Account` has mail enabled, _false_ otherwise. + */ + + + _createClass(Account, [{ + key: 'hasMail', + value: function hasMail() { + return this.hasDataFor.indexOf('mail') >= 0; + } + + /** + * Returns whether this `Account` supports calendars or not. + * + * @returns {Boolean} _true_ if and only if this `Account` has calendars enabled, _false_ otherwise. + */ + + }, { + key: 'hasCalendars', + value: function hasCalendars() { + return this.hasDataFor.indexOf('calendars') >= 0; + } + + /** + * Returns whether this `Account` supports contacts or not. + * + * @returns {Boolean} _true_ if and only if this `Account` has contacts enabled, _false_ otherwise. + */ + + }, { + key: 'hasContacts', + value: function hasContacts() { + return this.hasDataFor.indexOf('contacts') >= 0; + } + + /** + * Fetches all mailboxes of this _Account_.
+ * This will delegate to {@link Client#getMailboxes}, passing this Account's _id_ as the _accountId_ option. + * + * @param [options] {Object} The options object passed to {@link Client#getMailboxes}. + * Please note that the _accountId_ option will be overriden if defined. + * @returns {Promise} A promise that eventually resolves with an array of {@link Mailbox} instances. + * + * @see Client#getMailboxes + * @see PromiseProvider + */ + + }, { + key: 'getMailboxes', + value: function getMailboxes(options) { + options = options || {}; + options.accountId = this.id; + + return this._jmap.getMailboxes(options); + } + + /** + * Creates a JSON representation from this {@link Account}. + * + * @return JSON object with only owned properties and non-null default values. + */ + + }, { + key: 'toJSONObject', + value: function toJSONObject() { + return new _JSONBuilder2.default().append('name', this.name).append('isPrimary', this.isPrimary).append('isReadOnly', this.isReadOnly).append('hasDataFor', this.hasDataFor).build(); + } + + /** + * Creates an _Account_ from its JSON representation. + * + * @param jmap {Client} The {@link Client} instance passed to the _Account_ constructor. + * @param object {Object} The JSON representation of the _Account_, as a Javascript object. + * @param object.id {String} The identifier of the _Account_. + * + * @return {Account} + */ + + }], [{ + key: 'fromJSONObject', + value: function fromJSONObject(jmap, object) { + _Utils2.default.assertRequiredParameterIsPresent(object, 'object'); + + return new Account(jmap, object.id, object); + } + }]); + + return Account; +}(_Model3.default); + +exports.default = Account; +module.exports = exports['default']; + +},{"../utils/JSONBuilder.js":35,"../utils/Utils.js":36,"./Model.js":19}],6:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +var _JSONBuilder = require('../utils/JSONBuilder.js'); + +var _JSONBuilder2 = _interopRequireDefault(_JSONBuilder); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Attachment = function (_Model) { + _inherits(Attachment, _Model); + + /** + * This class represents a JMAP [Attachment]{@link http://jmap.io/spec.html#messages}.
+ * An _Attachment_ object holds all information of a given attachment of a {@link Message}. + * + * @constructor + * @extends Model + * + * @param jmap {Client} The {@link Client} instance that created the parent _Message_. + * @param blobId {String} The id of the binary data. + * @param [opts] {Object} The optional properties of this _Attachment_. + * @param [opts.url=null] {String} The URL to download the attachment. If not passed as a parameter, this will be deduced from + * the configured `downloadUrl` of the {@link Client} instance used to fetch the {@link Message} containing this _Attachment_. + * If the library does not find a reliable way of knowing the URL for this attachment, for any reason, the `url` property of this + * _Attachment_ instance will be set to `null`. + * @param [opts.type=''] {String} The content-type of the attachment. + * @param [opts.name=''] {String} The full file name. + * @param [opts.size=null] {Number} The size, in bytes, of the attachment when fully decoded. + * @param [opts.cid=null] {String} The id used within the message body to reference this attachment. + * @param [opts.isInline=false] {String} `true` if the attachment is referenced by a `cid:` link from within the HTML body of the message. + * @param [opts.width=null] {String} The width (in px) of the image, if the attachment is an image. + * @param [opts.height=null] {String} TThe height (in px) of the image, if the attachment is an image. + * + * @see Model + */ + function Attachment(jmap, blobId, opts) { + _classCallCheck(this, Attachment); + + var _this = _possibleConstructorReturn(this, (Attachment.__proto__ || Object.getPrototypeOf(Attachment)).call(this, jmap)); + + _Utils2.default.assertRequiredParameterIsPresent(blobId, 'blobId'); + + opts = opts || {}; + + _this.blobId = blobId; + _this.type = opts.type || null; + _this.name = opts.name || null; + _this.size = opts.size || 0; + _this.cid = opts.cid || null; + _this.isInline = opts.isInline || false; + _this.width = opts.width || null; + _this.height = opts.height || null; + _this.url = opts.url || null; + + // Some JMAP servers might return an already defined attachment URL, some others don't; the spec is vague about that + // If it is not provided by the server, we do a best effort to derive it from the configured download URL of our client + if (!_this.url && jmap.downloadUrl) { + _this.url = _Utils2.default.fillURITemplate(jmap.downloadUrl, { + blobId: _this.blobId, + name: _this.name || _this.blobId + }); + } + return _this; + } + + /** + * Gets a signed download URL for this {@link Attachment}. + * Details of this process can be found in [the spec](http://jmap.io/spec.html#downloading-an-attachment-through-a-signed-request). + *
+ * This mandates that `url` is defined on this {@link Attachment} instance, otherwise we cannot get a signed URL. + * + * @returns {Promise} A {@link Promise} eventually resolving to the signed download URL. + * + * @throws {Error} If this `Attachment` instance has no URL available. + */ + + + _createClass(Attachment, [{ + key: 'getSignedDownloadUrl', + value: function getSignedDownloadUrl() { + _Utils2.default.assertRequiredParameterIsPresent(this.url, 'url'); + + return this._jmap.transport.post(this.url, this._jmap._defaultHeaders(), null, true).then(_Utils2.default.appendQueryParameter.bind(null, this.url, 'access_token')); + } + + /** + * Creates a JSON representation from this model. + * + * @return JSON object with only owned properties and non default values. + */ + + }, { + key: 'toJSONObject', + value: function toJSONObject() { + return new _JSONBuilder2.default().appendIfDefined('blobId', this.blobId).appendIfDefined('type', this.type).appendIfDefined('name', this.name).appendIfDefined('size', this.size).appendIfDefined('cid', this.cid).appendIfDefined('width', this.width).appendIfDefined('height', this.height).appendIfDefined('url', this.url).appendIfDefined('isInline', this.isInline).build(); + } + + /** + * Creates an _Attachment_ from its JSON representation. + * + * @param jmap {Client} The {@link Client} instance used to fetch the parent {@link Message}. + * @param object {Object} The JSON representation of the _Attachment_, as a Javascript object. + * @param object.blobId {String} The id of the binary data for this _Attachment_. + * + * @return {Attachment} + */ + + }], [{ + key: 'fromJSONObject', + value: function fromJSONObject(jmap, object) { + _Utils2.default.assertRequiredParameterIsPresent(object, 'object'); + + return new Attachment(jmap, object.blobId, object); + } + }]); + + return Attachment; +}(_Model3.default); + +exports.default = Attachment; +module.exports = exports['default']; + +},{"../utils/JSONBuilder.js":35,"../utils/Utils.js":36,"./Model.js":19}],7:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +var _Constants = require('../utils/Constants.js'); + +var _Constants2 = _interopRequireDefault(_Constants); + +var _Account = require('./Account.js'); + +var _Account2 = _interopRequireDefault(_Account); + +var _ServerCapabilities = require('./ServerCapabilities.js'); + +var _ServerCapabilities2 = _interopRequireDefault(_ServerCapabilities); + +var _MailCapabilities = require('./MailCapabilities.js'); + +var _MailCapabilities2 = _interopRequireDefault(_MailCapabilities); + +var _JSONBuilder = require('../utils/JSONBuilder.js'); + +var _JSONBuilder2 = _interopRequireDefault(_JSONBuilder); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var AuthAccess = function (_Model) { + _inherits(AuthAccess, _Model); + + /** + * This class represents a JMAP [Auth Access Response]{@link http://jmap.io/spec-core.html#201-authentication-is-complete-access-token-created}. + * + * @constructor + * + * @param jmap {Client} The {@link Client} instance that created this _AuthAccess_. + * @param payload {Object} The server response of an auth access request. + */ + function AuthAccess(jmap, payload) { + _classCallCheck(this, AuthAccess); + + var _this = _possibleConstructorReturn(this, (AuthAccess.__proto__ || Object.getPrototypeOf(AuthAccess)).call(this, jmap)); + + _Utils2.default.assertRequiredParameterIsPresent(payload, 'payload'); + ['username', 'accessToken', 'signingId', 'signingKey', 'apiUrl', 'eventSourceUrl', 'uploadUrl', 'downloadUrl', 'accounts', 'capabilities'].forEach(function (property) { + _Utils2.default.assertRequiredParameterIsPresent(payload[property], property); + }); + + _this.username = payload.username; + _this.accessToken = payload.accessToken; + _this.signingId = payload.signingId; + _this.signingKey = payload.signingKey; + _this.apiUrl = payload.apiUrl; + _this.eventSourceUrl = payload.eventSourceUrl; + _this.uploadUrl = payload.uploadUrl; + _this.downloadUrl = payload.downloadUrl; + _this.capabilities = payload.capabilities; + _this.serverCapabilities = new _ServerCapabilities2.default(_this.capabilities[_Constants2.default.CORE_CAPABILITIES_URI] || {}); + _this.mailCapabilities = new _MailCapabilities2.default(_this.capabilities[_Constants2.default.MAIL_CAPABILITIES_URI] || {}); + + _this.accounts = {}; + for (var accountId in payload.accounts) { + _this.accounts[accountId] = _Account2.default.fromJSONObject(jmap, _extends({ id: accountId }, payload.accounts[accountId])); + } + return _this; + } + + /** + * Creates a JSON representation from this {@link AuthAccess}. + * + * @return JSON object with only owned properties and non-null default values. + */ + + + _createClass(AuthAccess, [{ + key: 'toJSONObject', + value: function toJSONObject() { + return new _JSONBuilder2.default().append('username', this.username).append('accessToken', this.accessToken).append('signingId', this.signingId).append('signingKey', this.signingKey).append('apiUrl', this.apiUrl).append('eventSourceUrl', this.eventSourceUrl).append('uploadUrl', this.uploadUrl).append('downloadUrl', this.downloadUrl).appendObject('accounts', this.accounts).appendObject('capabilities', this.capabilities).build(); + } + }]); + + return AuthAccess; +}(_Model3.default); + +exports.default = AuthAccess; +module.exports = exports['default']; + +},{"../utils/Constants.js":34,"../utils/JSONBuilder.js":35,"../utils/Utils.js":36,"./Account.js":5,"./MailCapabilities.js":14,"./Model.js":19,"./ServerCapabilities.js":21}],8:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +var _AuthMethod = require('./AuthMethod'); + +var _AuthMethod2 = _interopRequireDefault(_AuthMethod); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var AuthContinuation = function () { + /** + * This class represents a JMAP [Auth Continuation Response]{@link http://jmap.io/spec.html#authentication}. + * + * @constructor + * + * @param payload {Object} The server response of an initial auth request. + */ + function AuthContinuation(payload) { + _classCallCheck(this, AuthContinuation); + + _Utils2.default.assertRequiredParameterIsPresent(payload, 'payload'); + _Utils2.default.assertRequiredParameterIsPresent(payload.loginId, 'loginId'); + _Utils2.default.assertRequiredParameterIsArrayWithMinimumLength(payload.methods, 'methods'); + + this.loginId = payload.loginId; + this.methods = payload.methods.map(function (method) { + return new _AuthMethod2.default(method); + }); + this.prompt = payload.prompt || null; + } + + /** + * Getter for the AuthMethod instance matching the given authentication type + * + * @param type {String} The authentication type + * @return {AuthMethod} + */ + + + _createClass(AuthContinuation, [{ + key: 'getMethod', + value: function getMethod(type) { + _Utils2.default.assertRequiredParameterHasType(type, 'type', 'string'); + + var result = null; + + this.methods.forEach(function (authMethod) { + if (authMethod.type === type) { + result = authMethod; + } + }); + + if (!result) { + throw new Error('No AuthMethod of type "' + type + '" found'); + } + + return result; + } + + /** + * Checks if the given authentication type is supported by one of the registred auth methods + * + * @param type {String} The authentication type to check + * @return {Boolean} True if supported, False otherwise + */ + + }, { + key: 'supports', + value: function supports(type) { + _Utils2.default.assertRequiredParameterHasType(type, 'type', 'string'); + + var result = false; + + try { + this.getMethod(type); + result = true; + } catch (e) {} + + return result; + } + }]); + + return AuthContinuation; +}(); + +exports.default = AuthContinuation; +module.exports = exports['default']; + +},{"../utils/Utils.js":36,"./AuthMethod":9}],9:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var AuthMethod = +/** + * This class represents a JMAP [AuthMethod]{@link http://jmap.io/spec.html#getting-an-access-token}. + * + * @constructor + * + * @param payload {Object} The server response of POST request to the authentication URL. + */ + +function AuthMethod(payload) { + _classCallCheck(this, AuthMethod); + + _Utils2.default.assertRequiredParameterIsPresent(payload, 'payload'); + _Utils2.default.assertRequiredParameterHasType(payload.type, 'type', 'string'); + + _extends(this, payload); +}; + +exports.default = AuthMethod; +module.exports = exports['default']; + +},{"../utils/Utils.js":36}],10:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Capabilities = +/** + * This class represents an generic JMAP "capabilities" object. See {@link http://jmap.io/spec-core.html#getting-an-access-token*}.
+ * + * @param namespace {String} The namespace/identifier of the capabilities. + * @param [opts] {Object} The optional properties of this _Capabilities_. + */ +function Capabilities(namespace, opts) { + _classCallCheck(this, Capabilities); + + _Utils2.default.assertRequiredParameterIsPresent(namespace, 'namespace'); + + opts = opts || {}; + + this.ns = namespace; + _extends(this, opts); +}; + +exports.default = Capabilities; +module.exports = exports['default']; + +},{"../utils/Utils.js":36}],11:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var CreateMessageAck = function (_Model) { + _inherits(CreateMessageAck, _Model); + + /** + * This class should be used to wrap a create response item from a setMessages request.
+ * + * @constructor + * @extends Model + * + * @param jmap {Client} The {@link Client} instance that created this _OutboundMessage_. + * @param response {Object} The raw created response object. + * @param response.blobId {String} The server side generated blobId of the created message. + * @param response.size {Number} The server side size of the created message. + * @param [response.id=null] {String} The server side generated message id of the created message. + * @param [response.threadId=null] {String} The server side assigned threadId of the created message. + * + * @see Model + */ + function CreateMessageAck(jmap, response) { + _classCallCheck(this, CreateMessageAck); + + var _this = _possibleConstructorReturn(this, (CreateMessageAck.__proto__ || Object.getPrototypeOf(CreateMessageAck)).call(this, jmap)); + + _Utils2.default.assertRequiredParameterIsObject(response, 'response'); + _Utils2.default.assertRequiredParameterIsPresent(response.blobId, 'response.blobId'); + _Utils2.default.assertRequiredParameterHasType(response.size, 'response.size', 'number'); + + _this.id = response.id; + _this.blobId = response.blobId; + _this.size = response.size; + _this.threadId = response.threadId; + return _this; + } + + return CreateMessageAck; +}(_Model3.default); + +exports.default = CreateMessageAck; +module.exports = exports['default']; + +},{"../utils/Utils.js":36,"./Model.js":19}],12:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var EMailer = function () { + /** + * This class represents a JMAP [EMailer]{@link http://jmap.io/spec.html#messages}.
+ * An _EMailer_ object holds the name and email address of either a sender or a recipient of a {@link Message}. + * + * @param [opts] {Object} The optional properties of this _EMailer_. + * @param [opts.name=''] {String} The name of the emailer. + * @param [opts.email='@'] {String} The email address of the emailer. + */ + function EMailer(opts) { + _classCallCheck(this, EMailer); + + opts = opts || {}; + + this.name = opts.name || ''; + this.email = opts.email || '@'; // http://jmap.io/spec.html#messages + } + + /** + * This method returns the unknown _EMailer_, that is, an _EMailer_ instance with all fields set to defaults. + * + * @return {EMailer} The unknown _EMailer_. + */ + + + _createClass(EMailer, null, [{ + key: 'unknown', + value: function unknown() { + return new EMailer(); + } + + /** + * Creates a _EMailer_ from its JSON representation. + * + * @param jmap {Client} The {@link Client} instance that originates the _EMailer_ instance. Is actually ignored. + * @param object {Object} The JSON representation of the _EMailer_, as a Javascript object + * + * @return {EMailer} + */ + + }, { + key: 'fromJSONObject', + value: function fromJSONObject(jmap, object) { + return new EMailer(object); + } + }]); + + return EMailer; +}(); + +exports.default = EMailer; +module.exports = exports['default']; + +},{}],13:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _v = require('uuid/v4'); + +var _v2 = _interopRequireDefault(_v); + +var _FilterRuleConditions = require('./filterRules/FilterRuleConditions'); + +var _FilterRuleConditions2 = _interopRequireDefault(_FilterRuleConditions); + +var _FilterRuleActions = require('./filterRules/FilterRuleActions'); + +var _FilterRuleActions2 = _interopRequireDefault(_FilterRuleActions); + +var _Utils = require('../utils/Utils'); + +var _Utils2 = _interopRequireDefault(_Utils); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var FilterRule = function (_Model) { + _inherits(FilterRule, _Model); + + /** + * This class represents a JMAP [FilterRule]{@link http://jmap.io/spec.html}.
+ * The _FilterRule_ object represents the state of incoming message filtering for an account. + * + * @constructor + * @extends Model + * + * @param jmap {Client} The {@link Client} instance that created this _FilterRule_. + * @param name {String} The name of the rule + * + * NOTE: How to use and extend this model ? + * FilterRule is conceived so that a rule can be specified in a highly didactic way. For instance: + * + * new jmap.FilterRule(client, 'My filter') + * .when.from + * .value('admin@open-paas.org') + * .comparator(jmap.FilterRule.Comparator.EXACTLY_EQUALS) + * .then.moveTo + * .mailboxId('36e4d1c0-a473-11e8-aa26-bfb5d32a28f6'); + * + * To achive this, it uses the builder design pattern. To extend this model with new actions and conditions, + * you just need to create a new class that extends AbstractConditionAction and implements + * AbstractConditionAction#_init and AbstractConditionAction#_toJSONObject. + * + * AbstractConditionAction#_init is called by AbstractConditionAction' constructor and + * AbstractConditionAction#_toJSONObject is used to generate a JSON representation of the object. + * Then, just provide any useful property. + * + * To make the new condition or action available to the builder, you need to extend FilterRuleCondition + * (if defining a new condition) or FilterRuleAction (if defining a new action) + * + * @see Model + */ + function FilterRule(jmap, name) { + _classCallCheck(this, FilterRule); + + var _this = _possibleConstructorReturn(this, (FilterRule.__proto__ || Object.getPrototypeOf(FilterRule)).call(this, jmap)); + + _this.id = (0, _v2.default)(); + _this.name = name; + _this.filterCondition = null; + _this.filterAction = null; + return _this; + } + + _createClass(FilterRule, [{ + key: 'toJSONObject', + value: function toJSONObject() { + _Utils2.default.assertRequiredParameterIsPresent(this.filterCondition, '', 'Filter must have a condition. Use \'when\'.'); + _Utils2.default.assertRequiredParameterIsPresent(this.filterAction, '', 'Filter must have an action. Use \'then\'.'); + this.filterCondition._validate(); + this.filterAction._validate(); + + return { + id: this.id, + name: this.name, + condition: this.filterCondition._toJSONObject(), + action: this.filterAction._toJSONObject() + }; + } + }, { + key: 'then', + get: function get() { + return (0, _FilterRuleActions2.default)(this); + } + }, { + key: 'when', + get: function get() { + return (0, _FilterRuleConditions2.default)(this); + } + }], [{ + key: 'fromJSONObject', + value: function fromJSONObject(jmap, object) { + throw new Error('Not implemented'); + } + }]); + + return FilterRule; +}(_Model3.default); + +FilterRule.ID = 'singleton'; +FilterRule.Comparator = Object.freeze({ + CONTAINS: 'contains', + NOT_CONTAINS: 'not-contains', + EXACTLY_EQUALS: 'exactly-equals', + NOT_EXACTLY_EQUALS: 'not-exactly-equals' +}); + +exports.default = FilterRule; +module.exports = exports['default']; + +},{"../utils/Utils":36,"./Model.js":19,"./filterRules/FilterRuleActions":26,"./filterRules/FilterRuleConditions":27,"uuid/v4":39}],14:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _Capabilities2 = require('./Capabilities'); + +var _Capabilities3 = _interopRequireDefault(_Capabilities2); + +var _Constants = require('../utils/Constants'); + +var _Constants2 = _interopRequireDefault(_Constants); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var MailCapabilities = function (_Capabilities) { + _inherits(MailCapabilities, _Capabilities); + + /** + * This class represents a JMAP [MailCapabilities]{@link http://jmap.io/spec.html#accounts*}.
+ * An _MailCapabilities_ object describes mail-related capabilities of a JMAP server. + * + * @constructor + * @extends Capabilities + * + * @param [opts] {Object} The optional properties of this _MailCapabilities_. + * @param [opts.maxMailboxesPerMessage=null] {Number} The maximum number of mailboxes that can be can assigned to a single message. + * @param [opts.maxSizeMessageAttachments=0] {Number} The maximum total size of attachments, in bytes, allowed for messages. + * @param [opts.maxDelayedSend=0] {Number} The number in seconds of the maximum delay the server supports in sending. 0 if delayed send is not supported. + * @param [opts.messageListSortOptions=[]] {String[]} A list of all the message properties the server supports for sorting by. + * @param [opts.submissionExtensions={} {String[String[]]} Known safe-to-expose EHLO capabilities of the submission server. + * + * @see Capabilities + */ + function MailCapabilities(opts) { + _classCallCheck(this, MailCapabilities); + + opts = opts || {}; + + var _this = _possibleConstructorReturn(this, (MailCapabilities.__proto__ || Object.getPrototypeOf(MailCapabilities)).call(this, _Constants2.default.MAIL_CAPABILITIES_URI)); + + _this.maxMailboxesPerMessage = opts.maxMailboxesPerMessage || null; + _this.maxSizeMessageAttachments = opts.maxSizeMessageAttachments || 0; + _this.maxDelayedSend = opts.maxDelayedSend || 0; + _this.messageListSortOptions = opts.messageListSortOptions || []; + _this.submissionExtensions = opts.submissionExtensions || {}; + return _this; + } + + return MailCapabilities; +}(_Capabilities3.default); + +exports.default = MailCapabilities; +module.exports = exports['default']; + +},{"../utils/Constants":34,"./Capabilities":10}],15:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +var _MailboxRole = require('./MailboxRole.js'); + +var _MailboxRole2 = _interopRequireDefault(_MailboxRole); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Mailbox = function (_Model) { + _inherits(Mailbox, _Model); + + /** + * This class represents a JMAP [Mailbox]{@link http://jmap.io/spec.html#mailboxes}. + * + * @constructor + * @extends Model + * + * @param jmap {Client} The {@link Client} instance that created this _Mailbox_. + * @param id {String} The unique identifier of this _Mailbox_. + * @param name {String} The user-visible name (i.e.: display name) of this _Mailbox_. + * @param [opts] {Object} The optional properties of this _Mailbox_. + * @param [opts.namespace={}] {Object} The namespace give information about mailbox type and owner. + * @param [opts.parentId=null] {String} The _Mailbox_ id for the parent of this mailbox, or _null_ if this mailbox is at the top level. + * @param [opts.role=null] {String} The role of this mailbox, if it is a system mailbox. See the specification for the possible values. + * @param [opts.sharedWith={}] {Object} The sharedWith give information about mailbox shared and rights. + * @param [opts.sortOrder=0] {String} Defines the sort order of mailboxes when presented in the UI. + * @param [opts.mustBeOnlyMailbox=false] {Boolean} If _true_, messages in this mailbox may not also be in any other mailbox. + * @param [opts.mayReadItems=false] {Boolean} If _true_, may use this mailbox as part of a filter in a {@link Client#getMessageList} call. + * @param [opts.mayAddItems=false] {Boolean} If _true_, the user may add messages to this mailbox. + * @param [opts.mayRemoveItems=false] {Boolean} If _true_, the user may remove messages from this mailbox. + * @param [opts.mayCreateChild=false] {Boolean} If _true_, the user may create a _Mailbox_ with this _Mailbox_ as its parent. + * @param [opts.mayRename=false] {Boolean} If _true_, the user may rename this mailbox or make it a child of another mailbox. + * @param [opts.mayDelete=false] {Boolean} If _true_, the user may delete this mailbox. + * @param [opts.totalMessages=0] {Number} The number of messages in this mailbox. + * @param [opts.unreadMessages=0] {Number} The number of messages in this mailbox with _isUnread_=true and _isDraft_=false. + * @param [opts.totalThreads=0] {Number} The number of threads where at least one message in the thread is in this mailbox. + * @param [opts.unreadThreads=0] {Number} The number of threads where at least one message in the thread is in this mailbox with _isUnread_=true and _isDraft_=false. + * @param [opts.quotas={}] {Object} List of enforced quotas. 'STORAGE' for size quota and 'MESSAGE' for messages count. Each one provide used and max properties. + used (Number) number of messages, or size in bytes for storage + max (Number|null) maximum number of messages, or maximum size in bytes for storage. Null means unlimited + * @see Model + */ + function Mailbox(jmap, id, name, opts) { + _classCallCheck(this, Mailbox); + + var _this = _possibleConstructorReturn(this, (Mailbox.__proto__ || Object.getPrototypeOf(Mailbox)).call(this, jmap)); + + _Utils2.default.assertRequiredParameterIsPresent(id, 'id'); + _Utils2.default.assertRequiredParameterIsPresent(name, 'name'); + + opts = opts || {}; + + _this.id = id; + _this.name = name; + _this.namespace = opts.namespace || {}; + _this.parentId = opts.parentId || null; + _this.role = _MailboxRole2.default.fromRole(opts.role); + _this.sharedWith = opts.sharedWith || {}; + _this.sortOrder = opts.sortOrder || 0; + _this.mustBeOnlyMailbox = opts.mustBeOnlyMailbox || false; + _this.mayReadItems = opts.mayReadItems || false; + _this.mayAddItems = opts.mayAddItems || false; + _this.mayRemoveItems = opts.mayRemoveItems || false; + _this.mayCreateChild = opts.mayCreateChild || false; + _this.mayRename = opts.mayRename || false; + _this.mayDelete = opts.mayDelete || false; + _this.totalMessages = opts.totalMessages || 0; + _this.unreadMessages = opts.unreadMessages || 0; + _this.totalThreads = opts.totalThreads || 0; + _this.unreadThreads = opts.unreadThreads || 0; + _this.quotas = opts.quotas || {}; + return _this; + } + + /** + * Fetches a message list from this _Mailbox_.
+ * This will delegate to {@link Client#getMessageList}, passing the following filter: + * + * { + * inMailboxes: [] + * } + * + * @param [options] {Object} The options object passed to {@link Client#getMessageList}. + * Please note that the _filter_ option will be overriden if defined. + * @returns {Promise} A promise that eventually resolves with a {@link MessageList} instance. + * + * @see Client#getMessageList + * @see PromiseProvider + */ + + + _createClass(Mailbox, [{ + key: 'getMessageList', + value: function getMessageList(options) { + options = options || {}; + options.filter = { + inMailboxes: [this.id] + }; + + return this._jmap.getMessageList(options); + } + + /** + * Update this {@link Mailbox}. + * + * @param options {Object} The attribute to be updated in this {@link Mailbox}. + * @param options.name {String} The user-visible name of the _Mailbox_. + * @param [options.parentId = null] {String} The _Mailbox_ id for the parent of this mailbox, or _null_ if this mailbox is at the top level. + * + * @return {Promise} A {@link Promise}, as per {@link Client.updateMailbox}. + * + * @see Client#updateMailbox + */ + + }, { + key: 'update', + value: function update(options) { + return this._jmap.updateMailbox(this.id, options); + } + + /** + * Destroy this {@link Mailbox} on the server. + * + * @return {Promise} A {@link Promise}, as per {@link Client.destroyMailbox}. + * + * @see Client#destroyMailbox + */ + + }, { + key: 'destroy', + value: function destroy() { + return this._jmap.destroyMailbox(this.id); + } + + /** + * Creates a _Mailbox_ from its JSON representation. + * + * @param jmap {Client} The {@link Client} instance passed to the _Mailbox_ constructor. + * @param object {Object} The JSON representation of the _Mailbox_, as a Javascript object. + * @param object.id {String} The identifier of the _Mailbox_. + * @param object.name {String} The user-visible name of the _Mailbox_. + * + * @return {Mailbox} + */ + + }], [{ + key: 'fromJSONObject', + value: function fromJSONObject(jmap, object) { + _Utils2.default.assertRequiredParameterIsPresent(object, 'object'); + + return new Mailbox(jmap, object.id, object.name, object); + } + }]); + + return Mailbox; +}(_Model3.default); + +exports.default = Mailbox; +module.exports = exports['default']; + +},{"../utils/Utils.js":36,"./MailboxRole.js":16,"./Model.js":19}],16:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var MailboxRole = function () { + /** + * The MailboxRole class is simply a holder for predefined JMAP mailbox roles.
+ * It exposes class constants for every predefined roles (trash, inbox, etc.) + * + * @constructor + * + * @param role {String} The JMAP mailbox role. This is exposed as the `value` property. + * + * @see http://jmap.io/spec.html#mailboxes + */ + function MailboxRole(role) { + _classCallCheck(this, MailboxRole); + + this.value = role; + } + + /** + * Returns the class constant mapping to the given JMAP role, or {@link MailboxRole.UNKNOWN} + * if the role is undefined, null or isn't a predefined role. + * + * @param role {String} The JMAP role to find the {@link MailboxRole} for. + * + * @return {MailboxRole} + */ + + + _createClass(MailboxRole, null, [{ + key: 'fromRole', + value: function fromRole(role) { + if (role) { + for (var key in MailboxRole) { + if (MailboxRole.hasOwnProperty(key) && MailboxRole[key].value === role) { + return MailboxRole[key]; + } + } + } + + return MailboxRole.UNKNOWN; + } + }]); + + return MailboxRole; +}(); + +['inbox', 'archive', 'drafts', 'outbox', 'sent', 'trash', 'spam', 'templates'].forEach(function (role) { + MailboxRole[role.toUpperCase()] = new MailboxRole(role); +}); +MailboxRole.UNKNOWN = new MailboxRole(null); + +exports.default = MailboxRole; +module.exports = exports['default']; + +},{}],17:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _EMailer = require('./EMailer.js'); + +var _EMailer2 = _interopRequireDefault(_EMailer); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +var _Attachment = require('./Attachment.js'); + +var _Attachment2 = _interopRequireDefault(_Attachment); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Message = function (_Model) { + _inherits(Message, _Model); + + /** + * This class represents a JMAP [Message]{@link http://jmap.io/spec.html#messages}.
+ * When creating a new _Message_ instance, the following requirements must be met: + * * The _threadId_ must be defined (in JMAP, a _Message_ is always in a _Thread_) + * * The _mailboxIds_ must contain at least one element. + * + * @constructor + * @extends Model + * + * @param jmap {Client} The {@link Client} instance that created this _Message_. + * @param id {String} The unique identifier of this _Message_. + * @param blobId {String} The identifier representing the raw [@!RFC5322] message. + * @param threadId {String} The unique identifier of the _Thread_ this _Message_ is in. + * @param mailboxIds {String[]} The array of _Mailbox_ identifiers this _Message_ is present into. + * @param [opts] {Object} The optional properties of this _Message_. + * @param [opts.inReplyToMessageId=null] {String} The id of the _Message_ this _Message_ is a reply to. + * @param [opts.isUnread=false] {Boolean} Has the message not yet been read? This maps to the opposite of the \Seen flag in IMAP. + * @param [opts.isFlagged=false] {Boolean} Is the message flagged? This maps to the \Flagged flag in IMAP. + * @param [opts.isAnswered=false] {Boolean} Has the message been replied to? This maps to the \Answered flag in IMAP. + * @param [opts.isForwarded=false] {Boolean} Has the message been forwarded ?. + * @param [opts.isDraft=false] {Boolean} Is the message a draft? This maps to the \Draft flag in IMAP. + * @param [opts.hasAttachment=false] {Boolean} Does the message have any attachments? + * @param [opts.headers] {Object} A hash of header name to header value for all headers in the message. + * For headers that occur multiple times, the values are concatenated with a single new line (\n) character in between each one. + * @param [opts.from=null] {EMailer} The {@link EMailer} object representing the first identified sender of this _Message_. + * @param [opts.to=[{@link EMailer.unknown}]] {EMailer[]} The array of {@link EMailer} objects representing the _To:_ of this _Message_. + * @param [opts.cc=[{@link EMailer.unknown}]] {EMailer[]} The array of {@link EMailer} objects representing the _CC:_ of this _Message_. + * @param [opts.bcc=[{@link EMailer.unknown}]] {EMailer[]} The array of {@link EMailer} objects representing the _BCC:_ of this _Message_. + * @param [opts.replyTo={@link EMailer.unknown}] {EMailer[]} The array of {@link EMailer} objects representing the _Reply-To:_ of this _Message_. + * @param [opts.subject=null] {String} The subject of this _Message_. + * @param [opts.date=null] {Date} The date the _Message_ was sent (or saved, if the message is a draft). + * @param [opts.size=0] {String} The size in bytes of the whole message as counted by the server. + * @param [opts.preview=null] {String} Up to 256 characters of the beginning of a plain text version of the _Message_ body. + * @param [opts.textBody=null] {String} The plain text body part for the _Message_. + * @param [opts.htmlBody=null] {String} The HTML body part for the _Message_, if present. + * @param [opts.attachments=[]] {Attachment[]} An array of {@link Attachment} objects detailing all the attachments to the message. + * + * @see Model + * @see EMailer + */ + function Message(jmap, id, blobId, threadId, mailboxIds, opts) { + _classCallCheck(this, Message); + + var _this = _possibleConstructorReturn(this, (Message.__proto__ || Object.getPrototypeOf(Message)).call(this, jmap)); + + _Utils2.default.assertRequiredParameterIsPresent(id, 'id'); + _Utils2.default.assertRequiredParameterIsPresent(blobId, 'blobId'); + _Utils2.default.assertRequiredParameterIsPresent(threadId, 'threadId'); + _Utils2.default.assertRequiredParameterIsArrayWithMinimumLength(mailboxIds, 'mailboxIds', 1); + + opts = opts || {}; + + _this.id = id; + _this.blobId = blobId; + _this.threadId = threadId; + _this.mailboxIds = mailboxIds; + _this.inReplyToMessageId = opts.inReplyToMessageId || null; + _this.isUnread = opts.isUnread || false; + _this.isFlagged = opts.isFlagged || false; + _this.isAnswered = opts.isAnswered || false; + _this.isForwarded = opts.isForwarded || false; + _this.isDraft = opts.isDraft || false; + _this.hasAttachment = opts.hasAttachment || false; + _this.headers = opts.headers || {}; + _this.from = _Utils2.default._jsonArrayToModelList(jmap, _EMailer2.default, Array.isArray(opts.from) ? opts.from : [opts.from])[0]; + _this.to = _Utils2.default._jsonArrayToModelList(jmap, _EMailer2.default, opts.to); + _this.cc = _Utils2.default._jsonArrayToModelList(jmap, _EMailer2.default, opts.cc); + _this.bcc = _Utils2.default._jsonArrayToModelList(jmap, _EMailer2.default, opts.bcc); + _this.replyTo = opts.replyTo || []; + _this.subject = opts.subject || null; + _this.date = opts.date ? new Date(opts.date) : null; + _this.size = opts.size || 0; + _this.preview = opts.preview || null; + _this.textBody = opts.textBody || null; + _this.htmlBody = opts.htmlBody || null; + _this.attachments = _Utils2.default._jsonArrayToModelList(jmap, _Attachment2.default, opts.attachments); + return _this; + } + + /** + * Moves this {@link Message} to a different set of mailboxes. + * + * @param mailboxIds {String[]} The identifiers of the target mailboxes for the message. + * + * @return {Promise} A {@link Promise}, as per {@link Client.moveMessage}. + * + * @see Client#moveMessage + */ + + + _createClass(Message, [{ + key: 'move', + value: function move(mailboxIds) { + return this._jmap.moveMessage(this.id, mailboxIds); + } + + /** + * Moves this {@link Message} to the mailbox holding the given `role`.
+ * This will first do a JMAP request to find the mailbox with the given role, then a {@link Message#move} to move the message. + * + * @param role {MailboxRole|String} The desired mailbox role. + * + * @return {Promise} A {@link Promise}, as per {@link Message#move}. + * + * @see MailboxRole + * @see Client#getMailboxWithRole + */ + + }, { + key: 'moveToMailboxWithRole', + value: function moveToMailboxWithRole(role) { + var _this2 = this; + + return this._jmap.getMailboxWithRole(role).then(function (mailbox) { + return _this2.move([mailbox.id]); + }); + } + + /** + * Updates this {@link Message}. + * + * @param options {Object} The options to be updated in this {@link Message} as per {@link Client.updateMessage}. + * + * @return {Promise} A {@link Promise}, as per {@link Client.updateMessage}. + * + * @see Client#updateMessage + */ + + }, { + key: 'update', + value: function update(options) { + return this._jmap.updateMessage(this.id, options); + } + + /** + * Updates the isFlagged field of this {@link Message}. + * + * @param isFlagged {Boolean} The isFlagged field of the message. + * + * @return {Promise} A {@link Promise}, as per {@link Client.updateMessage}. + * + * @see Client#updateMessage + */ + + }, { + key: 'setIsFlagged', + value: function setIsFlagged(isFlagged) { + _Utils2.default.assertRequiredParameterHasType(isFlagged, 'isFlagged', 'boolean'); + + return this.update({ isFlagged: isFlagged }); + } + + /** + * Updates the isUnread field of this {@link Message}. + * + * @param isUnread {Boolean} The isUnread field of the message. + * + * @return {Promise} A {@link Promise}, as per {@link Client.updateMessage}. + * + * @see Client#updateMessage + */ + + }, { + key: 'setIsUnread', + value: function setIsUnread(isUnread) { + _Utils2.default.assertRequiredParameterHasType(isUnread, 'isUnread', 'boolean'); + + return this.update({ isUnread: isUnread }); + } + + /** + * Updates the isAnswered field of this {@link Message}. + * + * @param isAnswered {Boolean} The isAnswered field of the message. + * + * @return {Promise} A {@link Promise}, as per {@link Client.updateMessage}. + * + * @see Client#updateMessage + */ + + }, { + key: 'setIsAnswered', + value: function setIsAnswered(isAnswered) { + _Utils2.default.assertRequiredParameterHasType(isAnswered, 'isAnswered', 'boolean'); + + return this.update({ isAnswered: isAnswered }); + } + + /** + * Destroy this {@link Message} on the server. + * + * @return {Promise} A {@link Promise}, as per {@link Client.destroyMessage}. + * + * @see Client#destroyMessage + */ + + }, { + key: 'destroy', + value: function destroy() { + return this._jmap.destroyMessage(this.id); + } + + /** + * Creates a _Message_ from its JSON representation. + * + * @param jmap {Client} The {@link Client} instance passed to the _Message_ constructor. + * @param object {Object} The JSON representation of the _Message_, as a Javascript object. + * @param object.id {Object} The identifier of the _Message_. + * @param object.blobId {String} The identifier representing the raw [@!RFC5322] message. + * @param object.threadId {String} The identifier of the thread the _Message_ is in. + * @param object.mailboxIds {String[]} The array of _Mailbox_ identifiers the _Message_ is present into. + * + * @return {Message} + */ + + }], [{ + key: 'fromJSONObject', + value: function fromJSONObject(jmap, object) { + _Utils2.default.assertRequiredParameterIsPresent(object, 'object'); + + return new Message(jmap, object.id, object.blobId, object.threadId, object.mailboxIds, object); + } + }]); + + return Message; +}(_Model3.default); + +exports.default = Message; +module.exports = exports['default']; + +},{"../utils/Utils.js":36,"./Attachment.js":6,"./EMailer.js":12,"./Model.js":19}],18:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var MessageList = function (_Model) { + _inherits(MessageList, _Model); + + /** + * This class represents a JMAP [MessageList]{@link http://jmap.io/spec.html#messagelists}. + * + * @constructor + * @extends Model + * + * @param jmap {Client} The {@link Client} instance that created this _Mailbox_. + * @param [opts] {Object} The optional properties of this _Mailbox_. + * @param [opts.accountId=''] {String} The id of the {@link Account} used in the request that originated this _MessageList_. + * @param [opts.filter=null] {Object} The filter used in the request that originated this _MessageList_. + * @param [opts.sort=null] {Object} The sort properties used in the request that originated this _MessageList_. + * @param [opts.collapseThreads=false] {Boolean} The collapseThreads value used in the request that originated this _MessageList_. + * @param [opts.position=0] {Number} The 0-based index of the first result in the _threadIds_ array within the complete list. + * @param [opts.total=0] {Number} The total number of messages in the message list (given the filter and collapseThreads arguments). + * @param [opts.threadIds=[]] {String[]} The list of _Thread_ identifiers for each message in the list after filtering, sorting and collapsing threads. + * @param [opts.messageIds=[]] {String[]} The list of _Message_ identifiers for each message in the list after filtering, sorting and collapsing threads. + * + * @see Model + * @see Thread + * @see Message + */ + function MessageList(jmap, opts) { + _classCallCheck(this, MessageList); + + var _this = _possibleConstructorReturn(this, (MessageList.__proto__ || Object.getPrototypeOf(MessageList)).call(this, jmap)); + + opts = opts || {}; + + _this.accountId = opts.accountId || ''; + _this.filter = opts.filter || null; + _this.sort = opts.sort || null; + _this.collapseThreads = opts.collapseThreads || false; + _this.position = opts.position || 0; + _this.total = opts.total || 0; + _this.threadIds = opts.threadIds || []; + _this.messageIds = opts.messageIds || []; + return _this; + } + + /** + * Fetches all threads contained in this _MessageList_.
+ * This will delegate to {@link Client#getThreads}, passing this MessageList's _threadIds_ as the _ids_ option. + * + * @param [options] {Object} The options object passed to {@link Client#getThreads}. + * Please note that the _ids_ option will be overriden if defined. + * @returns {Promise} A promise that eventually resolves with an array of {@link Thread} instances. + * + * @see Client#getThreads + * @see PromiseProvider + */ + + + _createClass(MessageList, [{ + key: 'getThreads', + value: function getThreads(options) { + options = options || {}; + options.ids = this.threadIds; + + return this._jmap.getThreads(options); + } + + /** + * Fetches all messages contained in this _MessageList_.
+ * This will delegate to {@link Client#getMessages}, passing this MessageList's _messageIds_ as the _ids_ option. + * + * @param [options] {Object} The options object passed to {@link Client#getMessages}. + * Please note that the _ids_ option will be overriden if defined. + * @returns {Promise} A promise that eventually resolves with an array of {@link Message} instances. + * + * @see Client#getMessages + * @see PromiseProvider + */ + + }, { + key: 'getMessages', + value: function getMessages(options) { + options = options || {}; + options.ids = this.messageIds; + + return this._jmap.getMessages(options); + } + + /** + * Creates a _MessageList_ from its JSON representation. + * + * @param jmap {Client} The {@link Client} instance passed to the _MessageList_ constructor. + * @param object {Object} The JSON representation of the _MessageList_, as a Javascript object. + * + * @return {MessageList} + */ + + }], [{ + key: 'fromJSONObject', + value: function fromJSONObject(jmap, object) { + _Utils2.default.assertRequiredParameterIsPresent(object, 'object'); + + return new MessageList(jmap, object); + } + }]); + + return MessageList; +}(_Model3.default); + +exports.default = MessageList; +module.exports = exports['default']; + +},{"../utils/Utils.js":36,"./Model.js":19}],19:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Model = +/** + * The base class for all JMAP entities.
+ * When implementing new entities you should always try to inherit from this.
+ *
+ * You shouldn't use this constructor directly, but rather create instances of concrete implementations. + * + * @constructor + * @abstract + * + * @param jmap {Client} The {@link Client} instance that created this _Model_. This will be exposed as the **_jmap** property. + */ +function Model(jmap) { + _classCallCheck(this, Model); + + this._jmap = jmap; +}; + +exports.default = Model; +module.exports = exports['default']; + +},{}],20:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +var _Attachment = require('./Attachment.js'); + +var _Attachment2 = _interopRequireDefault(_Attachment); + +var _JSONBuilder = require('../utils/JSONBuilder.js'); + +var _JSONBuilder2 = _interopRequireDefault(_JSONBuilder); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var OutboundMessage = function (_Model) { + _inherits(OutboundMessage, _Model); + + /** + * This class represents a JMAP [Message]{@link http://jmap.io/spec.html#messages} but for client-to-server purpose.
+ * When creating a new _OutboundMessage_ instance, the following requirements must be met: + * * The _id_, _blobId_, _threadId_, _size_, _preview_, _hasAttachment_ and _attachedMessages_ must be not defined (it is set by the server upon creation) + * + * @constructor + * @extends Model + * + * @param jmap {Client} The {@link Client} instance that created this _OutboundMessage_. + * @param [opts] {Object} The optional properties of this _OutboundMessage_. + * @param [opts.mailboxIds=[]] {String[]} The array of _Mailbox_ identifiers which will contain this _OutboundMessage_. + * @param [opts.inReplyToMessageId=null] {String} The id of the _Message_ this _OutboundMessage_ is a reply to. + * @param [opts.isUnread=null] {Boolean} Has the message not yet been read? This maps to the opposite of the \Seen flag in IMAP. + * @param [opts.isFlagged=null] {Boolean} Is the message flagged? This maps to the \Flagged flag in IMAP. + * @param [opts.isAnswered=null] {Boolean} Has the message been replied to? This maps to the \Answered flag in IMAP. + * @param [opts.isDraft=null] {Boolean} Is the message a draft? This maps to the \Draft flag in IMAP. + * @param [opts.headers] {Object} A hash of header name to header value for all headers in the message. + * For headers that occur multiple times, the values are concatenated with a single new line (\n) character in between each one. + * @param [opts.from=null] {String} Overrides the value used as _From:_ in the headers. + * @param [opts.to=null] {String[]} Overrides the value used as _To:_ in the headers. + * @param [opts.cc=null] {String[]} Overrides the value used as _CC:_ in the headers. + * @param [opts.bcc=null] {String[]} Overrides the value used as _BCC:_ in the headers. + * @param [opts.replyTo=null] {String} Overrides the value used as _Reply-To:_ in the headers. + * @param [opts.subject=null] {String} The subject of this _OutboundMessage_. + * @param [opts.textBody=null] {String} The plain text body part. + * @param [opts.htmlBody=null] {String} The HTML body part. + * @param [opts.attachments=[]] {Attachment[]} An array of {@link Attachment} objects detailing all the attachments to the message. + * Attachments must first be uploaded using the standard upload mechanism. + * + * @see Model + */ + function OutboundMessage(jmap, opts) { + _classCallCheck(this, OutboundMessage); + + var _this = _possibleConstructorReturn(this, (OutboundMessage.__proto__ || Object.getPrototypeOf(OutboundMessage)).call(this, jmap)); + + opts = opts || {}; + + _this.mailboxIds = opts.mailboxIds || []; + _this.inReplyToMessageId = opts.inReplyToMessageId || null; + _this.isUnread = opts.isUnread; + _this.isFlagged = opts.isFlagged; + _this.isAnswered = opts.isAnswered; + _this.isDraft = opts.isDraft; + _this.headers = opts.headers || null; + _this.from = opts.from || null; + _this.to = opts.to || null; + _this.cc = opts.cc || null; + _this.bcc = opts.bcc || null; + _this.replyTo = opts.replyTo || null; + _this.subject = opts.subject || null; + _this.textBody = opts.textBody || null; + _this.htmlBody = opts.htmlBody || null; + _this.attachments = _Utils2.default._jsonArrayToModelList(jmap, _Attachment2.default, opts.attachments); + return _this; + } + + /** + * Creates a JSON representation from this model. + * + * @return JSON object with only owned properties and non default values. + */ + + + _createClass(OutboundMessage, [{ + key: 'toJSONObject', + value: function toJSONObject() { + return new _JSONBuilder2.default().appendIfNotEmpty('mailboxIds', this.mailboxIds).appendIfDefined('inReplyToMessageId', this.inReplyToMessageId).appendIfDefined('isUnread', this.isUnread).appendIfDefined('isFlagged', this.isFlagged).appendIfDefined('isAnswered', this.isAnswered).appendIfDefined('isDraft', this.isDraft).appendIfDefined('headers', this.headers).appendIfDefined('from', this.from).appendIfDefined('to', this.to).appendIfDefined('cc', this.cc).appendIfDefined('bcc', this.bcc).appendIfDefined('replyTo', this.replyTo).appendIfDefined('subject', this.subject).appendIfDefined('textBody', this.textBody).appendIfDefined('htmlBody', this.htmlBody).appendIfNotEmpty('attachments', this.attachments).build(); + } + }]); + + return OutboundMessage; +}(_Model3.default); + +exports.default = OutboundMessage; +module.exports = exports['default']; + +},{"../utils/JSONBuilder.js":35,"../utils/Utils.js":36,"./Attachment.js":6,"./Model.js":19}],21:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var ServerCapabilities = +/** + * This class represents a JMAP [ServerCapabilities]{@link http://jmap.io/spec-core.html#201-authentication-is-complete-access-token-created}.
+ * An _ServerCapabilities_ object describes general capabilities of a JMAP server. + * + * @constructor + * + * @param [opts] {Object} The optional properties of this _ServerCapabilities_. + * @param [opts.maxSizeUpload=0] {Number} The maximum file size, in bytes, that the server will accept for a single file upload. + * @param [opts.maxSizeRequest=0] {Number} The maximum size, in bytes, that the server will accept for a single request to the API endpoint. + * @param [opts.maxConcurrentUpload=1] {Number} The maximum number of concurrent requests the server will accept to the upload endpoint. + * @param [opts.maxConcurrentRequests=1] {Number} The maximum number of concurrent requests the server will accept to the API endpoint. + * @param [opts.maxCallsInRequest=1] {Number} The maximum number of method calls the server will accept in a single request to the API endpoint. + * @param [opts.maxObjectsInGet=0] {Number} The maximum number of objects that the client may request in a single getXXX type method call. + * @param [opts.maxObjectsInSet=0] {Number} The maximum number of objects the client may send to create, update or destroy in a single setXXX type method call. + */ +function ServerCapabilities(opts) { + _classCallCheck(this, ServerCapabilities); + + opts = opts || {}; + + this.maxSizeUpload = opts.maxSizeUpload || 0; + this.maxSizeRequest = opts.maxSizeRequest || 0; + this.maxConcurrentUpload = opts.maxConcurrentUpload || 1; + this.maxConcurrentRequests = opts.maxConcurrentRequests || 1; + this.maxCallsInRequest = opts.maxCallsInRequest || 1; + this.maxObjectsInGet = opts.maxObjectsInGet || 0; + this.maxObjectsInSet = opts.maxObjectsInSet || 0; +}; + +exports.default = ServerCapabilities; +module.exports = exports['default']; + +},{}],22:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +var _JmapError = require('../errors/JmapError'); + +var _JmapError2 = _interopRequireDefault(_JmapError); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var SetResponse = function (_Model) { + _inherits(SetResponse, _Model); + + /** + * This class represents a JMAP [xxxSet] {@link http://jmap.io/spec.html#setfoos}. + * + * @constructor + * @extends Model + * + * @param jmap {Client} The {@link Client} instance that created this _SetResponse_. + * @param [opts] {Object} The optional properties of this _SetResponse_. + * @param [opts.accountId=''] {String} The id of the {@link Account} used in the request that originated this _SetResponse_. + * @param [opts.oldState=''] {String} The state string that would have been returned by _getXXX_ before making the requested changes, + * or null if the server doesn’t know what the previous state string was. + * @param [opts.newState=''] {String[]} The state string that will now be returned by _getXXX_. + * @param [opts.created=[]] {String[]} A map of the creation id to an object containing any server-assigned properties of + * the _XXX_ object (including the id) for all successfully created records. + * @param [opts.updated=[]] {String[]} A list of _XXX_ ids for records that were successfully updated. + * @param [opts.destroyed=[]] {String[]} A list of _XXX_ ids for records that were successfully destroyed. + * @param [opts.MDNSent=[]] {String[]|null} A list of receipt request ids for receipt that were successfully sent. + * @param [opts.notCreated=[]] {String[]} A map of creation id to a SetError object for each _XXX_ that failed to be created. + * @param [opts.notUpdated=[]] {String[]} A map of _XXX_ id to a SetError object for each _XXX_ that failed to be updated. + * @param [opts.notDestroyed=[]] {String[]} A map of _XXX_ id to a SetError object for each _XXX_ that failed to be destroyed. + * @param [opts.MDNNotSent={}] {String[SetError]|null} A map of MDN request id to a SetError object for each receipt that failed to be sent, or null if all successful. + * + * @see Model + */ + function SetResponse(jmap, opts) { + _classCallCheck(this, SetResponse); + + var _this = _possibleConstructorReturn(this, (SetResponse.__proto__ || Object.getPrototypeOf(SetResponse)).call(this, jmap)); + + opts = opts || {}; + + _this.accountId = opts.accountId || null; + _this.oldState = opts.oldState || null; + _this.newState = opts.newState || ''; + _this.created = opts.created || {}; + _this.updated = opts.updated || []; + _this.destroyed = opts.destroyed || []; + _this.MDNSent = opts.MDNSent || []; + _this.notCreated = SetResponse._mapSetErrorsToJmapErrors(opts.notCreated || {}); + _this.notUpdated = SetResponse._mapSetErrorsToJmapErrors(opts.notUpdated || {}); + _this.notDestroyed = SetResponse._mapSetErrorsToJmapErrors(opts.notDestroyed || {}); + _this.MDNNotSent = SetResponse._mapSetErrorsToJmapErrors(opts.MDNNotSent || {}); + return _this; + } + + /** + * Creates a _SetResponse_ from its JSON representation. + * + * @param jmap {Client} The {@link Client} instance passed to the _SetResponse_ constructor. + * @param object {Object} The JSON representation of the _SetResponse_, as a Javascript object. + * + * @return {SetResponse} + */ + + + _createClass(SetResponse, null, [{ + key: 'fromJSONObject', + value: function fromJSONObject(jmap, object) { + _Utils2.default.assertRequiredParameterIsPresent(object, 'object'); + + return new SetResponse(jmap, object); + } + }, { + key: '_mapSetErrorsToJmapErrors', + value: function _mapSetErrorsToJmapErrors(errors) { + var newErrors = {}; + + for (var key in errors) { + if (errors.hasOwnProperty(key)) { + newErrors[key] = new _JmapError2.default(errors[key]); + } + } + + return newErrors; + } + }]); + + return SetResponse; +}(_Model3.default); + +exports.default = SetResponse; +module.exports = exports['default']; + +},{"../errors/JmapError":3,"../utils/Utils.js":36,"./Model.js":19}],23:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var Thread = function (_Model) { + _inherits(Thread, _Model); + + /** + * This class represents a JMAP [Thread]{@link http://jmap.io/spec.html#threads}. + * + * @constructor + * @extends Model + * + * @param jmap {Client} The {@link Client} instance that created this _Thread_. + * @param id {String} The unique identifier of this _Thread_. + * @param [opts] {Object} The optional properties of this _Thread_. + * @param [opts.messageIds=[]] {String[]} An array of message identifiers contained in this _Thread_. + * + * @see Model + */ + function Thread(jmap, id, opts) { + _classCallCheck(this, Thread); + + var _this = _possibleConstructorReturn(this, (Thread.__proto__ || Object.getPrototypeOf(Thread)).call(this, jmap)); + + _Utils2.default.assertRequiredParameterIsPresent(id, 'id'); + + opts = opts || {}; + + _this.id = id; + _this.messageIds = opts.messageIds || []; + return _this; + } + + /** + * Fetches all messages contained in this _Thread_.
+ * This will delegate to {@link Client#getMessages}, passing this Thread's _messageIds_ as the _ids_ option. + * + * @param [options] {Object} The options object passed to {@link Client#getMessages}. + * Please note that the _ids_ option will be overriden if defined. + * @returns {Promise} A promise that eventually resolves with an array of {@link Message} instances. + * + * @see Client#getMessages + * @see PromiseProvider + */ + + + _createClass(Thread, [{ + key: 'getMessages', + value: function getMessages(options) { + options = options || {}; + options.ids = this.messageIds; + + return this._jmap.getMessages(options); + } + + /** + * Updates the isFlagged field of all {@link Message}s of this {@link Thread}. + * + * @param isFlagged {Boolean} The isFlagged field of the thread. + * + * @return {Promise} A {@link Promise}, as per {@link Client.setMessages}. + * + * @see Client#setMessages + */ + + }, { + key: 'setIsFlagged', + value: function setIsFlagged(isFlagged) { + return this._flagAllMessages('isFlagged', isFlagged); + } + + /** + * Updates the isUnread field of this {@link Message}. + * + * @param isUnread {Boolean} The isUnread field of the thread. + * + * @return {Promise} A {@link Promise}, as per {@link Client.setMessages}. + * + * @see Client#setMessages + */ + + }, { + key: 'setIsUnread', + value: function setIsUnread(isUnread) { + return this._flagAllMessages('isUnread', isUnread); + } + + /** + * Moves this {@link Thread} to a different set of mailboxes. + * + * @param mailboxIds {String[]} The identifiers of the target mailboxes for the thread. + * + * @return {Promise} A {@link Promise}, as per {@link Client.setMessages}. + * + * @see Client#setMessages + */ + + }, { + key: 'move', + value: function move(mailboxIds) { + return this._updateAllMessages({ mailboxIds: mailboxIds }); + } + + /** + * Moves this {@link Thread} to the mailbox holding the given `role`.
+ * This will first do a JMAP request to find the mailbox with the given role, then a {@link Thread#move} to move the message. + * + * @param role {MailboxRole|String} The desired mailbox role. + * + * @return {Promise} A {@link Promise}, as per {@link Thread#move}. + * + * @see MailboxRole + * @see Client#getMailboxWithRole + */ + + }, { + key: 'moveToMailboxWithRole', + value: function moveToMailboxWithRole(role) { + var _this2 = this; + + return this._jmap.getMailboxWithRole(role).then(function (mailbox) { + return _this2.move([mailbox.id]); + }); + } + + /** + * Destroy this {@link Thread} on the server.
+ * This will internally destory all messages contained in this thread. + * + * @return {Promise} A {@link Promise}, as per {@link Client.destroyMessages}. + * + * @see Client#destroyMessages + */ + + }, { + key: 'destroy', + value: function destroy() { + return this._jmap.destroyMessages(this.messageIds); + } + }, { + key: '_updateAllMessages', + value: function _updateAllMessages(updates) { + var options = {}; + + this.messageIds.forEach(function (id) { + options[id] = updates; + }); + + return this._jmap.setMessages({ update: options }); + } + }, { + key: '_flagAllMessages', + value: function _flagAllMessages(flag, state) { + _Utils2.default.assertRequiredParameterHasType(state, 'state', 'boolean'); + + return this._updateAllMessages(_defineProperty({}, flag, state)); + } + + /** + * Creates a _Thread_ from its JSON representation. + * + * @param jmap {Client} The {@link Client} instance passed to the _Thread_ constructor. + * @param object {Object} The JSON representation of the _Thread_, as a Javascript object. + * @param object.id {String} The identifier of the _Thread_. + * + * @return {Thread} + */ + + }], [{ + key: 'fromJSONObject', + value: function fromJSONObject(jmap, object) { + _Utils2.default.assertRequiredParameterIsPresent(object, 'object'); + + return new Thread(jmap, object.id, object); + } + }]); + + return Thread; +}(_Model3.default); + +exports.default = Thread; +module.exports = exports['default']; + +},{"../utils/Utils.js":36,"./Model.js":19}],24:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Model2 = require('./Model.js'); + +var _Model3 = _interopRequireDefault(_Model2); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +var _JSONBuilder = require('../utils/JSONBuilder.js'); + +var _JSONBuilder2 = _interopRequireDefault(_JSONBuilder); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var VacationResponse = function (_Model) { + _inherits(VacationResponse, _Model); + + /** + * This class represents a JMAP [VacationResponse]{@link http://jmap.io/spec.html#vacation-response}.
+ * The _VacationResponse_ object represents the state of vacation-response related settings for an account. + * + * @constructor + * @extends Model + * + * @param jmap {Client} The {@link Client} instance that created this _VacationResponse_. + * @param [opts] {Object} The optional properties of this _VacationResponse_. + * @param [opts.isEnabled=false] {Boolean} Is the vacation response enabled? + * @param [opts.isActivated=false] {Boolean} Is the vacation response activated? + * @param [opts.fromDate=null] {Date} The date/time after which messages that arrive should receive the user’s vacation response, in UTC. + * @param [opts.toDate=null] {Date} The date/time after which messages that arrive should no longer receive the user’s vacation response, in UTC. + * @param [opts.subject=null] {String} The subject that will be used by the mail sent in response to messages when the vacation response is enabled. + * @param [opts.textBody=null] {Number} The plain text part of the message to send in response to messages when the vacation response is enabled. + * @param [opts.htmlBody=null] {String} The HTML part of the message to send in response to messages when the vacation response is enabled. + * + * @see Model + */ + function VacationResponse(jmap, opts) { + _classCallCheck(this, VacationResponse); + + var _this = _possibleConstructorReturn(this, (VacationResponse.__proto__ || Object.getPrototypeOf(VacationResponse)).call(this, jmap)); + + opts = opts || {}; + + _this.id = VacationResponse.ID; + _this.isEnabled = opts.isEnabled || false; + _this.isActivated = opts.isActivated || false; + _this.fromDate = opts.fromDate ? new Date(opts.fromDate) : null; + _this.toDate = opts.toDate ? new Date(opts.toDate) : null; + _this.subject = opts.subject || null; + _this.textBody = opts.textBody || null; + _this.htmlBody = opts.htmlBody || null; + return _this; + } + + /** + * Creates a JSON representation from this {@link VacationResponse}. + * + * @return JSON object with only owned properties and non-null default values. + */ + + + _createClass(VacationResponse, [{ + key: 'toJSONObject', + value: function toJSONObject() { + return new _JSONBuilder2.default().append('id', this.id).append('isEnabled', this.isEnabled).appendDateIfDefined('fromDate', this.fromDate).appendDateIfDefined('toDate', this.toDate).appendIfDefined('subject', this.subject).appendIfDefined('textBody', this.textBody).appendIfDefined('htmlBody', this.htmlBody).build(); + } + + /** + * Creates an _VacationResponse_ from its JSON representation. + * + * @param jmap {Client} The {@link Client} instance that created this _VacationResponse_. + * @param object {Object} The JSON representation of the _VacationResponse_, as a Javascript object. + * + * @return {VacationResponse} + */ + + }], [{ + key: 'fromJSONObject', + value: function fromJSONObject(jmap, object) { + _Utils2.default.assertRequiredParameterIsPresent(object, 'object'); + + return new VacationResponse(jmap, object); + } + }]); + + return VacationResponse; +}(_Model3.default); + +VacationResponse.ID = 'singleton'; // http://jmap.io/spec.html#vacation-response + +exports.default = VacationResponse; +module.exports = exports['default']; + +},{"../utils/JSONBuilder.js":35,"../utils/Utils.js":36,"./Model.js":19}],25:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var AbstractConditionAction = function () { + function AbstractConditionAction(filterRule) { + _classCallCheck(this, AbstractConditionAction); + + this.filterRule = filterRule; + this._init(); + } + + /** + * Do not override + * @returns {*} + */ + + + _createClass(AbstractConditionAction, [{ + key: 'toJSONObject', + + + /** + * Do not override + * @returns {*|JSON|{id, name, condition, action}} + */ + value: function toJSONObject() { + return this.filterRule.toJSONObject(); + } + + /** + * Initialises the object. Called by the constructor + * @private + */ + + }, { + key: '_init', + value: function _init() { + throw new Error('_init not implemented in child class'); + } + + /** + * Creates a JSON representation of the model + * @private + */ + + }, { + key: '_toJSONObject', + value: function _toJSONObject() { + throw new Error('_toJSONObject not implemented in child class'); + } + + /** + * Validates the object is correct with respect to JMap specification + * Will be called by FilterRule#toJSONObject + * @private + */ + + }, { + key: '_validate', + value: function _validate() { + throw new Error('_validate not implemented in child class'); + } + }, { + key: 'when', + get: function get() { + return this.filterRule.when; + } + + /** + * Do not override + * @returns {*} + */ + + }, { + key: 'then', + get: function get() { + return this.filterRule.then; + } + }]); + + return AbstractConditionAction; +}(); + +exports.default = AbstractConditionAction; +module.exports = exports['default']; + +},{}],26:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +exports.default = filterRuleActions; + +var _AbstractConditionAction = require('./AbstractConditionAction'); + +var _AbstractConditionAction2 = _interopRequireDefault(_AbstractConditionAction); + +var _Utils = require('../../utils/Utils'); + +var _Utils2 = _interopRequireDefault(_Utils); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var MoveTo = function (_AbstractConditionAct) { + _inherits(MoveTo, _AbstractConditionAct); + + function MoveTo() { + _classCallCheck(this, MoveTo); + + return _possibleConstructorReturn(this, (MoveTo.__proto__ || Object.getPrototypeOf(MoveTo)).apply(this, arguments)); + } + + _createClass(MoveTo, [{ + key: '_init', + value: function _init() { + this._mailboxId = null; + } + }, { + key: 'mailboxId', + value: function mailboxId(val) { + this._mailboxId = val; + + return this; + } + }, { + key: '_toJSONObject', + value: function _toJSONObject() { + return { + appendIn: { + mailboxIds: [this._mailboxId] + } + }; + } + }, { + key: '_validate', + value: function _validate() { + _Utils2.default.assertRequiredParameterIsPresent(this._mailboxId, '', 'Mailbox id is not set. Use mailboxId()'); + } + }]); + + return MoveTo; +}(_AbstractConditionAction2.default); + +function filterRuleActions(filterRule) { + /** + * Intermediate object to inject a action the to filter + * + * How to extend: + * Create a new condition class extending {AbstractConditionAction} and make it available + * by defining a new getter in the returned object. For instance: + * + * get moveTo() { + * filterRule.filterAction = new MoveTo(filterRule); + * return filterRule.filterAction; + * } + * + * get delete() { + * filterRule.filterCondition = new Delete(filterRule); + * return filterRule.filterCondition + * } + * + * @param filterRule {FilterRule} The filter that is being constructed + * @returns {AbstractConditionAction} The new condition + */ + return { + get moveTo() { + filterRule.filterAction = new MoveTo(filterRule); + + return filterRule.filterAction; + } + }; +} +module.exports = exports['default']; + +},{"../../utils/Utils":36,"./AbstractConditionAction":25}],27:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +exports.default = filterRuleConditions; + +var _AbstractConditionAction = require('./AbstractConditionAction'); + +var _AbstractConditionAction2 = _interopRequireDefault(_AbstractConditionAction); + +var _FilterRule = require('../FilterRule'); + +var _FilterRule2 = _interopRequireDefault(_FilterRule); + +var _Utils = require('../../utils/Utils'); + +var _Utils2 = _interopRequireDefault(_Utils); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var From = function (_AbstractConditionAct) { + _inherits(From, _AbstractConditionAct); + + function From() { + _classCallCheck(this, From); + + return _possibleConstructorReturn(this, (From.__proto__ || Object.getPrototypeOf(From)).apply(this, arguments)); + } + + _createClass(From, [{ + key: '_init', + value: function _init() { + this._comparator = null; + this._value = null; + } + }, { + key: 'value', + value: function value(val) { + this._value = val; + + return this; + } + }, { + key: 'comparator', + value: function comparator(val) { + if (!_Utils2.default.objectValuesIncludes(_FilterRule2.default.Comparator, val)) { + throw new Error('From#comparator(): ' + val + ' must be one of ' + _Utils2.default.objectValues(_FilterRule2.default.Comparator)); + } + this._comparator = val; + + return this; + } + }, { + key: '_toJSONObject', + value: function _toJSONObject() { + return { + field: 'from', + comparator: this._comparator, + value: this._value + }; + } + }, { + key: '_validate', + value: function _validate() { + _Utils2.default.assertRequiredParameterIsPresent(this._comparator, '', 'Comprator is not set. Use comparator()'); + _Utils2.default.assertRequiredParameterIsPresent(this._value, '', 'Value is not set. Use value()'); + } + }]); + + return From; +}(_AbstractConditionAction2.default); + +function filterRuleConditions(filterRule) { + /** + * Intermediate object to inject a condition the to filter + * + * How to extend: + * Create a new condition class extending {AbstractConditionAction} and make it available + * by defining a new getter in the returned obect. For instance: + * + * get from() { + * filterRule.filterCondition = new From(filterRule); + * return filterRule.filterCondition; + * } + * + * get subject() { + * filterRule.filterCondition = new Subject(filterRule); + * return filterRule.filterCondition + * } + * + * @param filterRule {FilterRule} The filter that is being constructed + * @returns {AbstractConditionAction} The new condition + */ + return { + get from() { + filterRule.filterCondition = new From(filterRule); + + return filterRule.filterCondition; + } + }; +} +module.exports = exports['default']; + +},{"../../utils/Utils":36,"../FilterRule":13,"./AbstractConditionAction":25}],28:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _PromiseProvider2 = require('./PromiseProvider.js'); + +var _PromiseProvider3 = _interopRequireDefault(_PromiseProvider2); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +/** + * A {@link PromiseProvider} implementation creating native ES6 Promises.
+ * This class supposes that the `Promise` class is available. + * + * @class ES6PromiseProvider + * + * @see PromiseProvider + */ +var ES6PromiseProvider = function (_PromiseProvider) { + _inherits(ES6PromiseProvider, _PromiseProvider); + + function ES6PromiseProvider() { + _classCallCheck(this, ES6PromiseProvider); + + return _possibleConstructorReturn(this, (ES6PromiseProvider.__proto__ || Object.getPrototypeOf(ES6PromiseProvider)).apply(this, arguments)); + } + + _createClass(ES6PromiseProvider, [{ + key: 'newPromise', + value: function newPromise(resolver) { + return new Promise(resolver); + } + }]); + + return ES6PromiseProvider; +}(_PromiseProvider3.default); + +exports.default = ES6PromiseProvider; +module.exports = exports['default']; + +},{"./PromiseProvider.js":29}],29:[function(require,module,exports){ +'use strict'; + +/** + * The {@link PromiseProvider} class is the base class for providers of {@link Promise} instances.
+ * A concrete implementation is required to implement {@link PromiseProvider#newPromise} so that this method + * returns a {@link Promise} that will be used by the library to do JMAP requests and other asynchronous things.
+ *
+ * This level of abstraction allows users of the library to plug in their own implementation in order to use their + * favorite {@link Promise} library. Implementations for [Q]{@link https://github.com/kriskowal/q} + * and native [ES6 Promises]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise} are provided. + * + * @abstract + * @class PromiseProvider + * + * @see ES6PromiseProvider + * @see QPromiseProvider + */ + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var PromiseProvider = function () { + function PromiseProvider() { + _classCallCheck(this, PromiseProvider); + } + + _createClass(PromiseProvider, [{ + key: 'newPromise', + + /** + * This method must be implemented by concrete {@link PromiseProvider} implementations in such a way that: + * * A {@link Promise} is created from the `resolver` argument and is returned. + * * The {@link Promise} will be fulfilled when the `resolve` function of the resolver is called. + * * The {@link Promise} will be rejected when the `reject` function of the resolver is called. + * + * @abstract + * + * @param resolver {Function} A {@link Function} with two arguments `resolve` and `reject`, both functions. + * The first argument fulfills the promise, the second argument rejects it. + * + * @return {Promise} + */ + value: function newPromise(resolver) { + throw new Error('PromiseProvider is an abstract class. Please use a concrete implementation.'); + } + }]); + + return PromiseProvider; +}(); + +exports.default = PromiseProvider; +module.exports = exports['default']; + +},{}],30:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _PromiseProvider2 = require('./PromiseProvider.js'); + +var _PromiseProvider3 = _interopRequireDefault(_PromiseProvider2); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +/** + * A {@link PromiseProvider} implementation creating [Q]{@link https://github.com/kriskowal/q} promises.
+ * This class requires `Q` to be installed as dependency. + * + * @class QPromiseProvider + * + * @see PromiseProvider + */ +var QPromiseProvider = function (_PromiseProvider) { + _inherits(QPromiseProvider, _PromiseProvider); + + function QPromiseProvider() { + _classCallCheck(this, QPromiseProvider); + + return _possibleConstructorReturn(this, (QPromiseProvider.__proto__ || Object.getPrototypeOf(QPromiseProvider)).apply(this, arguments)); + } + + _createClass(QPromiseProvider, [{ + key: 'newPromise', + value: function newPromise(resolver) { + return require('q').Promise(resolver); + } + }]); + + return QPromiseProvider; +}(_PromiseProvider3.default); + +exports.default = QPromiseProvider; +module.exports = exports['default']; + +},{"./PromiseProvider.js":29,"q":"q"}],31:[function(require,module,exports){ +'use strict'; + +/* global jQuery: false */ + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Transport2 = require('./Transport.js'); + +var _Transport3 = _interopRequireDefault(_Transport2); + +var _TransportError = require('../errors/TransportError'); + +var _TransportError2 = _interopRequireDefault(_TransportError); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var JQueryTransport = function (_Transport) { + _inherits(JQueryTransport, _Transport); + + /** + * A {@link Transport} implementation for [jQuery]{@link https://jquery.com/}.
+ * This class supposes that the `jQuery` global object is available. + * + * @constructor + * + * @param [promiseProvider=null] {PromiseProvider} A {@link PromiseProvider} implementation. + * + * @see Transport + */ + function JQueryTransport(promiseProvider) { + _classCallCheck(this, JQueryTransport); + + var _this = _possibleConstructorReturn(this, (JQueryTransport.__proto__ || Object.getPrototypeOf(JQueryTransport)).call(this)); + + _this.promiseProvider = promiseProvider; + return _this; + } + + _createClass(JQueryTransport, [{ + key: 'post', + value: function post(url, headers, data, raw) { + return this.promiseProvider.newPromise(function (resolve, reject) { + jQuery.ajax({ + url: url, + method: 'POST', + headers: headers, + data: raw ? data : JSON.stringify(data), + dataType: raw ? undefined : 'json', + processData: false, + jsonp: false + }).done(resolve).fail(function (xhr, statusText, err) { + return reject(new _TransportError2.default(err, xhr.status, xhr.responseText)); + }); + }); + } + }]); + + return JQueryTransport; +}(_Transport3.default); + +exports.default = JQueryTransport; +module.exports = exports['default']; + +},{"../errors/TransportError":4,"./Transport.js":33}],32:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Transport2 = require('./Transport'); + +var _Transport3 = _interopRequireDefault(_Transport2); + +var _TransportError = require('../errors/TransportError'); + +var _TransportError2 = _interopRequireDefault(_TransportError); + +var _Constants = require('../utils/Constants'); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var RequestTransport = function (_Transport) { + _inherits(RequestTransport, _Transport); + + /** + * A {@link Transport} implementation for [Request]{@link https://github.com/request/request}.
+ * This class requires `request` to be installed as dependency. + * + * @constructor + * + * @param [promiseProvider=null] {PromiseProvider} A {@link PromiseProvider} implementation. + * + * @see Transport + */ + function RequestTransport(promiseProvider) { + _classCallCheck(this, RequestTransport); + + var _this = _possibleConstructorReturn(this, (RequestTransport.__proto__ || Object.getPrototypeOf(RequestTransport)).call(this)); + + _this.promiseProvider = promiseProvider; + return _this; + } + + _createClass(RequestTransport, [{ + key: 'post', + value: function post(url, headers, data, raw) { + return this.promiseProvider.newPromise(function (resolve, reject) { + require('request')({ + url: url, + headers: headers, + method: 'POST', + body: data, + json: !raw + }, function (err, res, body) { + if (err || _Constants.SUCCESS_RESPONSE_CODES.indexOf(res.statusCode) < 0) { + return reject(new _TransportError2.default(err, res && res.statusCode, body)); + } + + resolve(body); + }); + }); + } + }]); + + return RequestTransport; +}(_Transport3.default); + +exports.default = RequestTransport; +module.exports = exports['default']; + +},{"../errors/TransportError":4,"../utils/Constants":34,"./Transport":33,"request":"request"}],33:[function(require,module,exports){ +'use strict'; + +/** + * The {@link Transport} class is the base class for providers of a HTTP transport layer.
+ * A concrete implementation is required to implement {@link Transport#post} so that this method returns a + * {@link Promise} that will be resolved or rejected depending on the result of the underlying HTTP request
+ * To create {@link Promise} instances, a {@link Transport} implementation should use a {@link PromiseProvider}. + * {@link Client} instances will automatically provide transports with the configured {@link PromiseProvider} as the + * `promiseProvider` property. + *
+ * This level of abstraction allows users of the library to plug in their own implementation in order to use their + * favorite HTTP transport library. Implementations for [Request]{@link https://github.com/request/request} + * and [jQuery]{@link https://jquery.com/} are provided. + * + * @abstract + * @class Transport + * + * @see JQueryTransport + * @see RequestTransport + * @see PromiseProvider + */ + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Transport = function () { + function Transport() { + _classCallCheck(this, Transport); + } + + _createClass(Transport, [{ + key: 'post', + + /** + * This method must be implemented by concrete {@link Transport} implementations in such a way that: + * * A HTTP POST request is made on `url` with the given `headers` and `data` (i.e.: payload) + * * A {@link Promise} is returned (`this.promiseProvider` will be available to create Promise instances) + * * The {@link Promise} is fulfilled when the HTTP request returns 200 (http://jmap.io/spec.html#jmap-over-https) + * * The {@link Promise} is rejected if the HTTP request fails, or if the return status code is not 200 + * * When the {@link Promise} is fulfilled, the raw JMAP response is returned + * + * @abstract + * + * @param url {String} The URL to POST to + * @param headers {Object} A hash of header names to header values that must be transmitted as part of the request + * @param data {*} The request payload, as a Javascript object. It's the responsibility of the {@link Transport} implementation + * to serialize the data as a JSON {@link String} whenever required. + * @param raw {Boolean} Whether the requests sends and expects raw (plain text) data instead of the default JSON. + * + * @return {Promise} + */ + value: function post(url, headers, data, raw) { + throw new Error('Transport is an abstract class. Please use a concrete implementation.'); + } + }]); + + return Transport; +}(); + +exports.default = Transport; +module.exports = exports['default']; + +},{}],34:[function(require,module,exports){ +'use strict'; + +/** + * The _Constants_ module exports a single object that is a collection of useful constants. + * + * @property VERSION {String} The version of this library + * + * @module Constants + */ + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = { + VERSION: '0.0.28-dev', + CLIENT_NAME: 'jmap-client (https://github.com/linagora/jmap-client)', + SUCCESS_RESPONSE_CODES: [200, 201], + ERROR: 'error', + CORE_CAPABILITIES_URI: 'http://jmap.io/spec-core.html', + MAIL_CAPABILITIES_URI: 'http://jmap.io/spec-mail.html' +}; +module.exports = exports['default']; + +},{}],35:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Utils = require('../utils/Utils.js'); + +var _Utils2 = _interopRequireDefault(_Utils); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var JSONBuilder = function () { + /** + * This class helps to create JSON representation from a model. + * Usage: + * + * return new JSONBuilder() + * .appendIfDefined('inReplyToMessageId', this.inReplyToMessageId) + * .appendIfDefined('isUnread', this.isUnread) + * .appendIfDefined('isFlagged', this.isFlagged) + * .build(); + * + * @constructor + **/ + function JSONBuilder() { + _classCallCheck(this, JSONBuilder); + + this.result = {}; + } + + /** + * Will append the _value_ to the building object, using the _name_ as key. + * + * @param name {String} The name to use as key. + * @param value {*} The value to append. + * + * @return this builder + **/ + + + _createClass(JSONBuilder, [{ + key: 'append', + value: function append(name, value) { + _Utils2.default.assertRequiredParameterIsPresent(name, 'name'); + _Utils2.default.assertRequiredParameterIsPresent(value, 'value'); + + this.result[name] = value; + + return this; + } + + /** + * If defined, it will append the _value_ to the building object, using the _name_ as key. + * + * @param name {String} The name to use as key. + * @param [value] {*} The value to append. + * + * @return this builder + **/ + + }, { + key: 'appendIfDefined', + value: function appendIfDefined(name, value) { + if (_Utils2.default.isDefined(value)) { + this.append(name, value); + } + + return this; + } + + /** + * If defined, it will append _date_ to the building object as an ISO Date String, using _name_ as the key. + * + * @param name {String} The name to use as key. + * @param [date] {Date} The `Date` to append. + * + * @return This {@link JSONBuilder} instance + * + * @see http://jmap.io/spec.html#the-date-datatypes + **/ + + }, { + key: 'appendDateIfDefined', + value: function appendDateIfDefined(name, date) { + if (_Utils2.default.isDefined(date)) { + _Utils2.default.assertRequiredParameterHasType(date, 'date', Date); + + this.append(name, date.toISOString().replace(/.\d+Z/, 'Z')); // Milliseconds should not be there, as per https://tools.ietf.org/html/rfc3339 + } + + return this; + } + + /** + * If defined and not empty, it will append the _value_ array to the building object, using the _name_ as key. + * + * @param name {String} The name to use as key. + * @param [value] {Array} The value to append. + * + * @return this builder + **/ + + }, { + key: 'appendIfNotEmpty', + value: function appendIfNotEmpty(name, value) { + if (value) { + _Utils2.default.assertRequiredParameterIsArrayWithMinimumLength(value, name); + if (value.length > 0) { + this.append(name, value.map(function (item) { + return item.toJSONObject ? item.toJSONObject() : item; + })); + } + } + + return this; + } + + /** + * Will append the _value_ object to the building object by recursively calling toJSONObject() + * on each child if an object. + * + * @param name {String} The name to use as key. + * @param value {Array} The `Object` to append + */ + + }, { + key: 'appendObject', + value: function appendObject(name, value) { + var key = void 0, + obj = {}; + + _Utils2.default.assertRequiredParameterIsObject(value, 'value'); + + for (key in value) { + if (value.hasOwnProperty(key)) { + if (_typeof(value[key]) === 'object' && value[key].toJSONObject) { + obj[key] = value[key].toJSONObject(); + } else { + obj[key] = value[key]; + } + } + } + + this.append(name, obj); + + return this; + } + + /** + * @return an object with all appended values + **/ + + }, { + key: 'build', + value: function build() { + return this.result; + } + }]); + + return JSONBuilder; +}(); + +exports.default = JSONBuilder; +module.exports = exports['default']; + +},{"../utils/Utils.js":36}],36:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _Constants = require('./Constants'); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Utils = function () { + /** + * This class contains some useful utility methods.
+ * The Utils class cannot be instantiated (its constructor will throw if called), all its methods are static. + * + * @constructor + */ + function Utils() { + _classCallCheck(this, Utils); + + throw new Error('The Utils class cannot be instantiated.'); + } + + /** + * Check is the `parameter` is not undefined and not null. + * + * @param parameter {*} The parameter to check. + * + * @return {Boolean} True if `parameter` is not undefined and not null. + */ + + + _createClass(Utils, null, [{ + key: 'isDefined', + value: function isDefined(parameter) { + return typeof parameter !== 'undefined' && parameter !== null; + } + + /** + * Asserts that the given `parameter` is present (read: truthy).
+ * This method is intended to be called when you need to validate input parameters of functions. + * + * @param parameter {*} The parameter to validate. + * @param name {String} The name of the parameter, as given to the calling function. + * This is used to format the error message contained by the thrown {@link Error}. + * @param message {String} Optionnal alternative message to display when error + * + * @return {*} The validated parameter, as-is. + * + * @throws {Error} If the parameter is not defined. + */ + + }, { + key: 'assertRequiredParameterIsPresent', + value: function assertRequiredParameterIsPresent(parameter, name) { + var message = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + + message = message || 'The ' + name + ' parameter is required'; + if (!Utils.isDefined(parameter)) { + throw new Error(message); + } + + return parameter; + } + + /** + * Asserts that the given `parameter` is present and is an object.
+ * This method is intended to be called when you need to validate input parameters of functions. + * + * @param parameter {*} The parameter to validate. + * @param name {String} The name of the parameter, as given to the calling function. + * This is used to format the error message contained by the thrown {@link Error}. + * + * @return {*} The validated parameter, as-is. + * + * @throws {Error} If the parameter is not defined or is not an object. + */ + + }, { + key: 'assertRequiredParameterIsObject', + value: function assertRequiredParameterIsObject(parameter, name) { + Utils.assertRequiredParameterIsPresent(parameter, name); + + if ((typeof parameter === 'undefined' ? 'undefined' : _typeof(parameter)) !== 'object' || Array.isArray(parameter)) { + throw new Error('The "' + name + '" parameter is not an object.'); + } + + return parameter; + } + + /** + * Asserts that the given `parameter` is present and has the expected type.
+ * This method is intended to be called when you need to validate input parameters of functions. + * Examples: + * assertRequiredParameterHasType(5, 'name', 'number') => returns 5 + * assertRequiredParameterHasType({}, 'name', CustomClass) => throws an Error + * + * @param parameter {*} The parameter to validate. + * @param name {String} The name of the parameter, as given to the calling function. + * This is used to format the error message contained by the thrown {@link Error}. + * @param type {String|Type} The expected type of the parameter. + * + * @return {*} The validated parameter, as-is. + * + * @throws {Error} If the parameter is not defined or is not an object. + */ + + }, { + key: 'assertRequiredParameterHasType', + value: function assertRequiredParameterHasType(parameter, name, type) { + Utils.assertRequiredParameterIsPresent(parameter, name); + + if (typeof type === 'string') { + if ((typeof parameter === 'undefined' ? 'undefined' : _typeof(parameter)) !== type) { + throw new Error('The "' + name + '" parameter has not the expected type: ' + type); + } + } else if (!(parameter instanceof type)) { + throw new Error('The "' + name + '" parameter has not the expected type: ' + type); + } + + return parameter; + } + + /** + * Asserts that the given `parameter` is an {@link Array} with a minimum length.
+ * This method is intended to be called when you need to validate input parameters of functions. + * + * @param parameter {*} The parameter to validate. + * @param name {String} The name of the parameter, as given to the calling function. + * This is used to format the error message contained by the thrown {@link Error}. + * @param [length=0] {Number} The minimum required length of the array. + * + * @return {*} The validated parameter, as-is. + * + * @throws {Error} If the parameter is not an array of does not have the minimum length. + */ + + }, { + key: 'assertRequiredParameterIsArrayWithMinimumLength', + value: function assertRequiredParameterIsArrayWithMinimumLength(parameter, name, length) { + if (!Array.isArray(parameter)) { + throw new Error('The "' + name + '" parameter must be an Array.'); + } + + if (length && parameter.length < length) { + throw new Error('The "' + name + '" parameter must have at least ' + length + ' element(s).'); + } + + return parameter; + } + + /** + * Asserts that the given `data` is a valid JMAP response.
+ * This method is intended to be called by instances of {@link Client}, or by any other object making JMAP requests, + * when validation of the response is required.
+ *
+ * The following checks are made by this method: + * * `data` is defined and is an array + * * `data` has one or more elements, and all elements are arrays + * * `data[0][0]` is either + * * the expected response string (computed with the help of the `request` parameter) + * * 'error' + * * an unknown response + * * `data[0][1]` exists + * + * @param request {String} The JMAP request to check the response for. This should be a valid JMAP request name. + * @param data {*} The JMAP response to validate. + * + * @return {*} The data, as-is, if it is detected as a valid JMAP response. + * + * @throws {Error} If the received data is not a valid JMAP response. + */ + + }, { + key: 'assertValidJMAPResponse', + value: function assertValidJMAPResponse(request, data) { + function allArrayElementsAreArray(array) { + return array.filter(function (element) { + return !Array.isArray(element); + }).length === 0; + } + + if (!data || !Array.isArray(data)) { + throw new Error('Expected an array as the JMAP response for a "' + request + '" request.'); + } + + if (data.length === 0 || !allArrayElementsAreArray(data)) { + throw new Error('Expected an array of exactly 1 array element as the JMAP response for a "' + request + '" request.'); + } + + var response = data[0][0], + expectedResponse = Utils._expectedResponseFor(request); + + if (response !== _Constants.ERROR && expectedResponse && response !== expectedResponse) { + throw new Error('Expected "' + expectedResponse + '" as the JMAP response for a "' + request + '" request, but got "' + response + '".'); + } + + if (!data[0][1]) { + throw new Error('The JMAP response for a "' + request + '" request should return some data.'); + } + + return data; + } + + /** + * Capitalizes the given {@link String}, that is, returns the same string with the first character in uppercase.
+ * If `undefined`, `null`, the _empty string_ or something else that a string is given, the argument is returned as-is. + * + * @param str {String} The {@link String} to capitalize. + * + * @return {String} The capitalized {@link String}. + */ + + }, { + key: 'capitalize', + value: function capitalize(str) { + if (!str || typeof str !== 'string') { + return str; + } + + return str.charAt(0).toUpperCase() + str.substring(1); + } + + /** + * Fills a URI template by substituting variables by their corresponding values.
+ * This supports Level 1 URI templates *only*, as per [this RFC](https://tools.ietf.org/html/rfc6570#section-1.2). + * + * @param uri {String} The URI template to fill. + * @param parameters {Object} A hash of name/value pairs used for variables substitution. + * + * @return {String} The filled URI template. + */ + + }, { + key: 'fillURITemplate', + value: function fillURITemplate(uri, parameters) { + Utils.assertRequiredParameterIsPresent(uri, 'uri'); + + if (!parameters) { + return uri; + } + + return uri.replace(/{(.+?)}/g, function (match, variable) { + var value = parameters[variable]; + + return value ? encodeURIComponent(value) : match; + }); + } + + /** + * Appends a query parameter to an existing URL, taking care of existing query parameters.
+ * This method returns `uri` as-is if `key` or `value` is not defined. + * + * @param uri {String} The URI to modify. + * @param key {String} The name of the parameter to append. + * @param value {String} The value of the parameter to append. + * + * @returns {String} The modified URI. + */ + + }, { + key: 'appendQueryParameter', + value: function appendQueryParameter(uri, key, value) { + if (!uri || !key || !value) { + return uri; + } + + return uri + (uri.indexOf('?') > -1 ? '&' : '?') + encodeURIComponent(key) + '=' + encodeURIComponent(value); + } + + /** + * Returns the value at _index_ in the given `Array`, or the default value if the array is undefined, null, + * if _index_ is negative or there is not enough elements in the array. + * + * @param array The `Array` to get the value from. + * @param index The index of the desired value. + * @param defaultValue The default value to return if the element cannot be found in the array. + * + * @returns {*} The found value or the given default. + */ + + }, { + key: 'nthElementOrDefault', + value: function nthElementOrDefault(array, index, defaultValue) { + if (Array.isArray(array) && index >= 0 && array.length > index) { + return array[index]; + } + + return defaultValue; + } + + /** + * Can't make babel pollyfills to work with Karma. This is a hackity hack. + * Object.values is part of ES7 standard. + * @param object + */ + + }, { + key: 'objectValues', + value: function objectValues(object) { + return Object.keys(object).map(function (key) { + return object[key]; + }); + } + }, { + key: 'objectValuesIncludes', + value: function objectValuesIncludes(object, value) { + return Utils.objectValues(object).indexOf(value) >= 0; + } + }, { + key: '_jsonArrayToModelList', + value: function _jsonArrayToModelList(jmap, Model, array, filter) { + if (!Array.isArray(array)) { + return []; + } + + if (filter) { + array = array.filter(filter); + } + + return array.map(Model.fromJSONObject.bind(null, jmap)); + } + }, { + key: '_nullOrNewInstance', + value: function _nullOrNewInstance(value, Model) { + return value && new Model(value) || null; + } + }, { + key: '_expectedResponseFor', + value: function _expectedResponseFor(request) { + return { + getAccounts: 'accounts', + getMailboxes: 'mailboxes', + getMessageList: 'messageList', + getThreads: 'threads', + getMessages: 'messages', + setMessages: 'messagesSet', + setMailboxes: 'mailboxesSet', + getVacationResponse: 'vacationResponse', + setVacationResponse: 'vacationResponseSet', + getFilter: 'filter', + setFilter: 'filterSet' + }[request]; + } + }]); + + return Utils; +}(); + +exports.default = Utils; +module.exports = exports['default']; + +},{"./Constants":34}],37:[function(require,module,exports){ +/** + * Convert array of 16 byte values to UUID string format of the form: + * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX + */ +var byteToHex = []; +for (var i = 0; i < 256; ++i) { + byteToHex[i] = (i + 0x100).toString(16).substr(1); +} + +function bytesToUuid(buf, offset) { + var i = offset || 0; + var bth = byteToHex; + // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4 + return ([bth[buf[i++]], bth[buf[i++]], + bth[buf[i++]], bth[buf[i++]], '-', + bth[buf[i++]], bth[buf[i++]], '-', + bth[buf[i++]], bth[buf[i++]], '-', + bth[buf[i++]], bth[buf[i++]], '-', + bth[buf[i++]], bth[buf[i++]], + bth[buf[i++]], bth[buf[i++]], + bth[buf[i++]], bth[buf[i++]]]).join(''); +} + +module.exports = bytesToUuid; + +},{}],38:[function(require,module,exports){ +// Unique ID creation requires a high quality random # generator. In the +// browser this is a little complicated due to unknown quality of Math.random() +// and inconsistent support for the `crypto` API. We do the best we can via +// feature-detection + +// getRandomValues needs to be invoked in a context where "this" is a Crypto +// implementation. Also, find the complete implementation of crypto on IE11. +var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) || + (typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto)); + +if (getRandomValues) { + // WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto + var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef + + module.exports = function whatwgRNG() { + getRandomValues(rnds8); + return rnds8; + }; +} else { + // Math.random()-based (RNG) + // + // If all else fails, use Math.random(). It's fast, but is of unspecified + // quality. + var rnds = new Array(16); + + module.exports = function mathRNG() { + for (var i = 0, r; i < 16; i++) { + if ((i & 0x03) === 0) r = Math.random() * 0x100000000; + rnds[i] = r >>> ((i & 0x03) << 3) & 0xff; + } + + return rnds; + }; +} + +},{}],39:[function(require,module,exports){ +var rng = require('./lib/rng'); +var bytesToUuid = require('./lib/bytesToUuid'); + +function v4(options, buf, offset) { + var i = buf && offset || 0; + + if (typeof(options) == 'string') { + buf = options === 'binary' ? new Array(16) : null; + options = null; + } + options = options || {}; + + var rnds = options.random || (options.rng || rng)(); + + // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` + rnds[6] = (rnds[6] & 0x0f) | 0x40; + rnds[8] = (rnds[8] & 0x3f) | 0x80; + + // Copy bytes to buffer, if provided + if (buf) { + for (var ii = 0; ii < 16; ++ii) { + buf[i + ii] = rnds[ii]; + } + } + + return buf || bytesToUuid(rnds); +} + +module.exports = v4; + +},{"./lib/bytesToUuid":37,"./lib/rng":38}]},{},[1])(1) +}); \ No newline at end of file diff --git a/dist/jmap-client.min.js b/dist/jmap-client.min.js new file mode 100644 index 0000000..95e0b06 --- /dev/null +++ b/dist/jmap-client.min.js @@ -0,0 +1,3 @@ +!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.jmap=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g0){var c=a.notDestroyed[b[0]],d=c.type+" ("+c.description+")";throw new Error("Failed to destroy "+b[0]+", the reason is: "+d)}})}},{key:"getMailboxWithRole",value:function(a,b){if(a instanceof C.default||(a=C.default.fromRole(a)),a===C.default.UNKNOWN)throw new Error("A valid role is required to find a mailbox by role");return this._jmapRequest("getMailboxes",b).then(function(b){for(var c=0;c1?a:a[0]})}},{key:"_handleResponse",value:function(a,b){var c=a[0],d=this["_handle"+k.default.capitalize(c)+"Response"];return d?d.bind(this)(a,b):a[1]}},{key:"_handleErrorResponse",value:function(a,b){throw new M.default(a[1],b)}},{key:"_handleListResponse",value:function(a,b,c){return k.default._jsonArrayToModelList(this,b,a[1].list,c)}},{key:"_handleSetResponse",value:function(a){return s.default.fromJSONObject(this,a[1])}},{key:"_handleAccountsResponse",value:function(a){return this._handleListResponse(a,m.default)}},{key:"_handleThreadsResponse",value:function(a){return this._handleListResponse(a,u.default)}},{key:"_handleMessagesResponse",value:function(a){return this._handleListResponse(a,w.default,function(a){try{return k.default.assertRequiredParameterIsArrayWithMinimumLength(a.mailboxIds,"mailboxIds",1)}catch(a){return!1}})}},{key:"_handleMailboxesResponse",value:function(a){return this._handleListResponse(a,o.default)}},{key:"_handleMailboxesSetResponse",value:function(a){return this._handleSetResponse(a)}},{key:"_handleMessageListResponse",value:function(a){return q.default.fromJSONObject(this,a[1])}},{key:"_handleMessagesSetResponse",value:function(a){return this._handleSetResponse(a)}},{key:"_handleVacationResponseResponse",value:function(a){return this._handleListResponse(a,K.default)}},{key:"_handleVacationResponseSetResponse",value:function(a){return this._handleSetResponse(a)}}]),a}();c.default=P,b.exports=c.default},{"../errors/JmapError":3,"../models/FilterRule":13,"../utils/Constants.js":34,"./../models/Account.js":5,"./../models/AuthAccess.js":7,"./../models/AuthContinuation.js":8,"./../models/CreateMessageAck.js":11,"./../models/Mailbox.js":15,"./../models/MailboxRole.js":16,"./../models/Message.js":17,"./../models/MessageList.js":18,"./../models/OutboundMessage.js":20,"./../models/SetResponse.js":22,"./../models/Thread.js":23,"./../models/VacationResponse":24,"./../promises/ES6PromiseProvider.js":28,"./../utils/Utils.js":36}],3:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{default:a}}function e(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function f(a,b){if(!a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!b||"object"!=typeof b&&"function"!=typeof b?a:b}function g(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)}function h(a){function b(){a.apply(this,arguments)}return b.prototype=Object.create(a.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),Object.setPrototypeOf?Object.setPrototypeOf(b,a):b.__proto__=a,b}Object.defineProperty(c,"__esModule",{value:!0});var i=function(){function a(a,b){for(var c=0;c=0}},{key:"hasCalendars",value:function(){return this.hasDataFor.indexOf("calendars")>=0}},{key:"hasContacts",value:function(){return this.hasDataFor.indexOf("contacts")>=0}},{key:"getMailboxes",value:function(a){return a=a||{},a.accountId=this.id,this._jmap.getMailboxes(a)}},{key:"toJSONObject",value:function(){return(new n.default).append("name",this.name).append("isPrimary",this.isPrimary).append("isReadOnly",this.isReadOnly).append("hasDataFor",this.hasDataFor).build()}}],[{key:"fromJSONObject",value:function(a,c){return l.default.assertRequiredParameterIsPresent(c,"object"),new b(a,c.id,c)}}]),b}(j.default);c.default=o,b.exports=c.default},{"../utils/JSONBuilder.js":35,"../utils/Utils.js":36,"./Model.js":19}],6:[function(a,b,c){"use strict";function d(a){return a&&a.__esModule?a:{default:a}}function e(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function f(a,b){if(!a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!b||"object"!=typeof b&&"function"!=typeof b?a:b}function g(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)}Object.defineProperty(c,"__esModule",{value:!0});var h=function(){function a(a,b){for(var c=0;c0&&this.append(a,b.map(function(a){return a.toJSONObject?a.toJSONObject():a}))),this}},{key:"appendObject",value:function(a,b){var c=void 0,d={};i.default.assertRequiredParameterIsObject(b,"value");for(c in b)b.hasOwnProperty(c)&&("object"===f(b[c])&&b[c].toJSONObject?d[c]=b[c].toJSONObject():d[c]=b[c]);return this.append(a,d),this}},{key:"build",value:function(){return this.result}}]),a}();c.default=j,b.exports=c.default},{"../utils/Utils.js":36}],36:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(c,"__esModule",{value:!0});var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},f=function(){function a(a,b){for(var c=0;c2&&void 0!==arguments[2]?arguments[2]:null;if(d=d||"The "+c+" parameter is required",!a.isDefined(b))throw new Error(d);return b}},{key:"assertRequiredParameterIsObject",value:function(b,c){if(a.assertRequiredParameterIsPresent(b,c),"object"!==("undefined"==typeof b?"undefined":e(b))||Array.isArray(b))throw new Error('The "'+c+'" parameter is not an object.');return b}},{key:"assertRequiredParameterHasType",value:function(b,c,d){if(a.assertRequiredParameterIsPresent(b,c),"string"==typeof d){if(("undefined"==typeof b?"undefined":e(b))!==d)throw new Error('The "'+c+'" parameter has not the expected type: '+d)}else if(!(b instanceof d))throw new Error('The "'+c+'" parameter has not the expected type: '+d);return b}},{key:"assertRequiredParameterIsArrayWithMinimumLength",value:function(a,b,c){if(!Array.isArray(a))throw new Error('The "'+b+'" parameter must be an Array.');if(c&&a.length-1?"&":"?")+encodeURIComponent(b)+"="+encodeURIComponent(c):a}},{key:"nthElementOrDefault",value:function(a,b,c){return Array.isArray(a)&&b>=0&&a.length>b?a[b]:c}},{key:"objectValues",value:function(a){return Object.keys(a).map(function(b){return a[b]})}},{key:"objectValuesIncludes",value:function(b,c){return a.objectValues(b).indexOf(c)>=0}},{key:"_jsonArrayToModelList",value:function(a,b,c,d){return Array.isArray(c)?(d&&(c=c.filter(d)),c.map(b.fromJSONObject.bind(null,a))):[]}},{key:"_nullOrNewInstance",value:function(a,b){return a&&new b(a)||null}},{key:"_expectedResponseFor",value:function(a){return{getAccounts:"accounts",getMailboxes:"mailboxes",getMessageList:"messageList",getThreads:"threads",getMessages:"messages",setMessages:"messagesSet",setMailboxes:"mailboxesSet",getVacationResponse:"vacationResponse",setVacationResponse:"vacationResponseSet",getFilter:"filter",setFilter:"filterSet"}[a]}}]),a}();c.default=h,b.exports=c.default},{"./Constants":34}],37:[function(a,b,c){function d(a,b){var c=b||0,d=e;return[d[a[c++]],d[a[c++]],d[a[c++]],d[a[c++]],"-",d[a[c++]],d[a[c++]],"-",d[a[c++]],d[a[c++]],"-",d[a[c++]],d[a[c++]],"-",d[a[c++]],d[a[c++]],d[a[c++]],d[a[c++]],d[a[c++]],d[a[c++]]].join("")}for(var e=[],f=0;f<256;++f)e[f]=(f+256).toString(16).substr(1);b.exports=d},{}],38:[function(a,b,c){var d="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(d){var e=new Uint8Array(16);b.exports=function(){return d(e),e}}else{var f=new Array(16);b.exports=function(){for(var a,b=0;b<16;b++)0===(3&b)&&(a=4294967296*Math.random()),f[b]=a>>>((3&b)<<3)&255;return f}}},{}],39:[function(a,b,c){function d(a,b,c){var d=b&&c||0;"string"==typeof a&&(b="binary"===a?new Array(16):null,a=null),a=a||{};var g=a.random||(a.rng||e)();if(g[6]=15&g[6]|64,g[8]=63&g[8]|128,b)for(var h=0;h<16;++h)b[d+h]=g[h];return b||f(g)}var e=a("./lib/rng"),f=a("./lib/bytesToUuid");b.exports=d},{"./lib/bytesToUuid":37,"./lib/rng":38}]},{},[1])(1)}); \ No newline at end of file diff --git a/doc/api/API.js.html b/doc/api/API.js.html new file mode 100644 index 0000000..b06a210 --- /dev/null +++ b/doc/api/API.js.html @@ -0,0 +1,131 @@ + + + + + JSDoc: Source: API.js + + + + + + + + + + +
+ +

Source: API.js

+ + + + + + +
+
+
'use strict';
+
+/**
+ * The _API_ module is the entry point of the library.<br />
+ * It exports a single {@link Object} that is exposed as, either:
+ * * A global `jmap` variable when jmap-client included in a web page through a `script` tag
+ * * A NodeJS module when jmap-client is `require`'d in a NodeJS application
+ *
+ * When extending the library with new models, utility classes, etc. don't forget to update this module
+ * so that your new code gets exposed in the public API.<br />
+ * <br />
+ * The exported object has the following properties:
+ *
+ * @property Client {Client} The {@link Client} class
+ * @property Utils {Utils} The {@link Utils} class
+ * @property JSONBuilder {JSONBuilder} The {@link JSONBuilder} class helping to serialize model to json
+ * @property PromiseProvider {PromiseProvider} The {@link PromiseProvider} class
+ * @property ES6PromiseProvider { ES6PromiseProvider} The {@link  ES6PromiseProvider} class
+ * @property QPromiseProvider { QPromiseProvider} The {@link  QPromiseProvider} class
+ * @property Transport { Transport} The {@link  Transport} class
+ * @property JQueryTransport { JQueryTransport} The {@link  JQueryTransport} class
+ * @property RequestTransport { RequestTransport} The {@link  RequestTransport} class
+ * @property Model { Model} The {@link  Model} class
+ * @property Account { Account} The {@link  Account} class
+ * @property EMailer { EMailer} The {@link  EMailer} class
+ * @property Mailbox { Mailbox} The {@link  Mailbox} class
+ * @property MessageList { MessageList} The {@link  MessageList} class
+ * @property Message { Message} The {@link  Message} class
+ * @property OutboundMessage {OutboundMessage} The {@link OutboundMessage} class
+ * @property CreateMessageAck {CreateMessageAck} The {@link CreateMessageAck} class
+ * @property Thread { Thread} The {@link  Thread} class
+ * @property MailboxRole {MailboxRole} The {@link MailboxRole} class
+ * @property SetResponse {SetResponse} The {@link SetResponse} class
+ * @property AuthAccess {AuthAccess} The {@link AuthAccess} class
+ * @property AuthContinuation {AuthContinuation} The {@link AuthContinuation} class
+ * @property Constants {Constants} The {@link module:Constants|Constants} object
+ * @property Attachment {Attachment} The {@link Attachment} class
+ * @property Capabilities {Capabilities} The {@link Capabilities} class
+ * @property MailCapabilities {MailCapabilities} The {@link MailCapabilities} class
+ * @property ServerCapabilities {ServerCapabilities} The {@link ServerCapabilities} class
+ * @property VacationResponse {VacationResponse} The {@link VacationResponse} class
+ * @property TransportError {TransportError} The {@link TransportError} class
+ * @property JmapError {JmapError} The {@link JmapError} class
+ *
+ * @module API
+ */
+export default {
+  Account: require('./models/Account'),
+  Attachment: require('./models/Attachment'),
+  AuthAccess: require('./models/AuthAccess'),
+  AuthContinuation: require('./models/AuthContinuation'),
+  AuthMethod: require('./models/AuthMethod'),
+  Capabilities: require('./models/Capabilities'),
+  Client: require('./client/Client'),
+  CreateMessageAck: require('./models/CreateMessageAck'),
+  Constants: require('./utils/Constants'),
+  EMailer: require('./models/EMailer'),
+  ES6PromiseProvider: require('./promises/ES6PromiseProvider'),
+  FilterRule: require('./models/FilterRule'),
+  JmapError: require('./errors/JmapError'),
+  JQueryTransport: require('./transport/JQueryTransport'),
+  JSONBuilder: require('./utils/JSONBuilder'),
+  Mailbox: require('./models/Mailbox'),
+  MailboxRole: require('./models/MailboxRole'),
+  MailCapabilities: require('./models/MailCapabilities'),
+  Message: require('./models/Message'),
+  MessageList: require('./models/MessageList'),
+  Model: require('./models/Model'),
+  OutboundMessage: require('./models/OutboundMessage'),
+  PromiseProvider: require('./promises/PromiseProvider'),
+  QPromiseProvider: require('./promises/QPromiseProvider'),
+  RequestTransport: require('./transport/RequestTransport'),
+  ServerCapabilities: require('./models/ServerCapabilities'),
+  SetResponse: require('./models/SetResponse'),
+  Thread: require('./models/Thread'),
+  Transport: require('./transport/Transport'),
+  TransportError: require('./errors/TransportError'),
+  Utils: require('./utils/Utils'),
+  VacationResponse: require('./models/VacationResponse'),
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/Account.html b/doc/api/Account.html new file mode 100644 index 0000000..44e7797 --- /dev/null +++ b/doc/api/Account.html @@ -0,0 +1,1295 @@ + + + + + JSDoc: Class: Account + + + + + + + + + + +
+ +

Class: Account

+ + + + + + +
+ +
+ +

Account

+ + +
+ +
+
+ + + + + +

new Account(jmap, id, optsopt)

+ + + + + +
+

This class represents a JMAP Account.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
jmap + + +Client + + + + + + + + + +

The Client instance that created this Account.

id + + +String + + + + + + + + + +

The unique identifier of this Account.

opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this Account.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
name + + +String + + + + + + <optional>
+ + + + + +
+ + '' + +

The name of this Account.

isPrimary + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

Whether this Account is the primary email account.

isReadOnly + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

Whether the entire Account is read-only

hasDataFor + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

A list of the data profiles available in this account +server.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) fromJSONObject(jmap, object) → {Account}

+ + + + + +
+

Creates an Account from its JSON representation.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance passed to the Account constructor.

object + + +Object + + + +

The JSON representation of the Account, as a Javascript object.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + +

The identifier of the Account.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Account + + +
+
+ + + + + + + + + + +

getMailboxes(optionsopt) → {Promise}

+ + + + + +
+

Fetches all mailboxes of this Account.
+This will delegate to Client#getMailboxes, passing this Account's id as the accountId option.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
options + + +Object + + + + + + <optional>
+ + + + + +

The options object passed to Client#getMailboxes. + Please note that the accountId option will be overriden if defined.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A promise that eventually resolves with an array of Mailbox instances.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

hasCalendars() → {Boolean}

+ + + + + +
+

Returns whether this Account supports calendars or not.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

true if and only if this Account has calendars enabled, false otherwise.

+
+ + + +
+
+ Type +
+
+ +Boolean + + +
+
+ + + + + + + + + + +

hasContacts() → {Boolean}

+ + + + + +
+

Returns whether this Account supports contacts or not.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

true if and only if this Account has contacts enabled, false otherwise.

+
+ + + +
+
+ Type +
+
+ +Boolean + + +
+
+ + + + + + + + + + +

hasMail() → {Boolean}

+ + + + + +
+

Returns whether this Account supports mail or not.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

true if and only if this Account has mail enabled, false otherwise.

+
+ + + +
+
+ Type +
+
+ +Boolean + + +
+
+ + + + + + + + + + +

toJSONObject()

+ + + + + +
+

Creates a JSON representation from this Account.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

JSON object with only owned properties and non-null default values.

+
+ + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/Attachment.html b/doc/api/Attachment.html new file mode 100644 index 0000000..52bcb56 --- /dev/null +++ b/doc/api/Attachment.html @@ -0,0 +1,1102 @@ + + + + + JSDoc: Class: Attachment + + + + + + + + + + +
+ +

Class: Attachment

+ + + + + + +
+ +
+ +

Attachment

+ + +
+ +
+
+ + + + + +

new Attachment(jmap, blobId, optsopt)

+ + + + + +
+

This class represents a JMAP Attachment.
+An Attachment object holds all information of a given attachment of a Message.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
jmap + + +Client + + + + + + + + + +

The Client instance that created the parent Message.

blobId + + +String + + + + + + + + + +

The id of the binary data.

opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this Attachment.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
url + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The URL to download the attachment. If not passed as a parameter, this will be deduced from + the configured downloadUrl of the Client instance used to fetch the Message containing this Attachment. + If the library does not find a reliable way of knowing the URL for this attachment, for any reason, the url property of this + Attachment instance will be set to null.

type + + +String + + + + + + <optional>
+ + + + + +
+ + '' + +

The content-type of the attachment.

name + + +String + + + + + + <optional>
+ + + + + +
+ + '' + +

The full file name.

size + + +Number + + + + + + <optional>
+ + + + + +
+ + null + +

The size, in bytes, of the attachment when fully decoded.

cid + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The id used within the message body to reference this attachment.

isInline + + +String + + + + + + <optional>
+ + + + + +
+ + false + +

true if the attachment is referenced by a cid: link from within the HTML body of the message.

width + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The width (in px) of the image, if the attachment is an image.

height + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

TThe height (in px) of the image, if the attachment is an image.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) fromJSONObject(jmap, object) → {Attachment}

+ + + + + +
+

Creates an Attachment from its JSON representation.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance used to fetch the parent Message.

object + + +Object + + + +

The JSON representation of the Attachment, as a Javascript object.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
blobId + + +String + + + +

The id of the binary data for this Attachment.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Attachment + + +
+
+ + + + + + + + + + +

getSignedDownloadUrl() → {Promise}

+ + + + + +
+

Gets a signed download URL for this Attachment. +Details of this process can be found in the spec. +
+This mandates that url is defined on this Attachment instance, otherwise we cannot get a signed URL.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Throws:
+ + + +
+
+
+

If this Attachment instance has no URL available.

+
+
+
+
+
+
+ Type +
+
+ +Error + + +
+
+
+
+
+ + + + + +
Returns:
+ + +
+

A Promise eventually resolving to the signed download URL.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

toJSONObject()

+ + + + + +
+

Creates a JSON representation from this model.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

JSON object with only owned properties and non default values.

+
+ + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/AuthAccess.html b/doc/api/AuthAccess.html new file mode 100644 index 0000000..d22e0d4 --- /dev/null +++ b/doc/api/AuthAccess.html @@ -0,0 +1,330 @@ + + + + + JSDoc: Class: AuthAccess + + + + + + + + + + +
+ +

Class: AuthAccess

+ + + + + + +
+ +
+ +

AuthAccess

+ + +
+ +
+
+ + + + + +

new AuthAccess(jmap, payload)

+ + + + + +
+

This class represents a JMAP Auth Access Response.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance that created this AuthAccess.

payload + + +Object + + + +

The server response of an auth access request.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

toJSONObject()

+ + + + + +
+

Creates a JSON representation from this AuthAccess.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

JSON object with only owned properties and non-null default values.

+
+ + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/AuthContinuation.html b/doc/api/AuthContinuation.html new file mode 100644 index 0000000..6cacb75 --- /dev/null +++ b/doc/api/AuthContinuation.html @@ -0,0 +1,517 @@ + + + + + JSDoc: Class: AuthContinuation + + + + + + + + + + +
+ +

Class: AuthContinuation

+ + + + + + +
+ +
+ +

AuthContinuation

+ + +
+ +
+
+ + + + + +

new AuthContinuation(payload)

+ + + + + +
+

This class represents a JMAP Auth Continuation Response.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
payload + + +Object + + + +

The server response of an initial auth request.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

getMethod(type) → {AuthMethod}

+ + + + + +
+

Getter for the AuthMethod instance matching the given authentication type

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + +

The authentication type

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +AuthMethod + + +
+
+ + + + + + + + + + +

supports(type) → {Boolean}

+ + + + + +
+

Checks if the given authentication type is supported by one of the registred auth methods

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
type + + +String + + + +

The authentication type to check

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

True if supported, False otherwise

+
+ + + +
+
+ Type +
+
+ +Boolean + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/AuthMethod.html b/doc/api/AuthMethod.html new file mode 100644 index 0000000..a4a7b87 --- /dev/null +++ b/doc/api/AuthMethod.html @@ -0,0 +1,211 @@ + + + + + JSDoc: Class: AuthMethod + + + + + + + + + + +
+ +

Class: AuthMethod

+ + + + + + +
+ +
+ +

AuthMethod

+ + +
+ +
+
+ + + + + +

new AuthMethod(payload)

+ + + + + +
+

This class represents a JMAP AuthMethod.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
payload + + +Object + + + +

The server response of POST request to the authentication URL.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/Capabilities.html b/doc/api/Capabilities.html new file mode 100644 index 0000000..d41e143 --- /dev/null +++ b/doc/api/Capabilities.html @@ -0,0 +1,254 @@ + + + + + JSDoc: Class: Capabilities + + + + + + + + + + +
+ +

Class: Capabilities

+ + + + + + +
+ +
+ +

Capabilities

+ + +
+ +
+
+ + + + + +

new Capabilities(namespace, optsopt)

+ + + + + +
+

This class represents an generic JMAP "capabilities" object. See http://jmap.io/spec-core.html#getting-an-access-token*.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
namespace + + +String + + + + + + + + + +

The namespace/identifier of the capabilities.

opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this Capabilities.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/Client.html b/doc/api/Client.html new file mode 100644 index 0000000..85a3979 --- /dev/null +++ b/doc/api/Client.html @@ -0,0 +1,5833 @@ + + + + + JSDoc: Class: Client + + + + + + + + + + +
+ +

Class: Client

+ + + + + + +
+ +
+ +

Client

+ + +
+ +
+
+ + + + + +

new Client(transport, promiseProvideropt)

+ + + + + +
+

The Client class is the main entry point for sending JMAP requests to a remote server.
+It uses a fluent API so that it's easy to chain calls. JMAP requests are sent using one of the getXXX methods +that map to their equivalent in the JMAP specification. For instance, if you want to do a getAccounts request, +you'll use the Client#getAccounts method.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
transport + + +Transport + + + + + + + + + + + +

The Transport instance used to send HTTP requests.

promiseProvider + + +PromiseProvider + + + + + + <optional>
+ + + + + +
+ + ES6PromiseProvider + +

The PromiseProvider implementation to use.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

authenticate(username, deviceName, continuationCallback) → {Promise}

+ + + + + +
+

Implement the 2-step JMAP authentication protocol.
+This method abstract the two authentication steps:

+
    +
  1. query the JMAP server to get a continuation token
  2. +
  3. query the JMAP server with the continuation token (and password), to get the final accessToken.
  4. +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
username + + +String + + + +

The username to authenticate with

deviceName + + +String + + + +

A unique device name

continuationCallback + + +function + + + +

A function that takes an AuthContinuation + object as argument, and should return a promise, that will eventually resolve with an + object denoting the chosen authentication method and the optional password (if method == password).

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that will eventually be resovled with a AuthAccess object

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

authExternal(username, deviceName, continuationCallback) → {Promise}

+ + + + + +
+

Implement the JMAP external authentication protocol.
+This method abstract the two authentication steps:

+
    +
  1. query the JMAP server to get a continuation token
  2. +
  3. query the JMAP server with the continuation token, to get the final accessToken.
  4. +
+


+Between those two steps, a user provided function wil be called to handle the external +authentication part. +
+This method returns a promise that will eventually be resovled with a AuthAccess object. +It's the responsability of the caller to then set the AuthToken using for example: +

+
client.withAuthenticationToken(authAccess.accessToken);
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
username + + +String + + + +

The username of the user to authenticate.

deviceName + + +String + + + +

A unique device name

continuationCallback + + +function + + + +

A function that takes an AuthContinuation object as argument, and should return a promise, that will resolve once the external authentication is complete.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that will eventually be resovled with a AuthAccess object

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

authPassword(username, password, deviceName) → {Promise}

+ + + + + +
+

Implement the JMAP password authentication protocol.
+This method abstract the two authentication steps:

+
    +
  1. query the JMAP server to get a continuation token
  2. +
  3. query the JMAP server with the continuation token and the password, to get the final accessToken.
  4. +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
username + + +String + + + +

The username of the user to authenticate

password + + +String + + + +

The password of the user to authenticate

deviceName + + +String + + + +

A unique device name

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that will eventually be resovled with a AuthAccess object

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

createMailbox(name, parentIdopt) → {Promise}

+ + + + + +
+

Creates a mailbox by sending a setMailboxes JMAP request.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
name + + +String + + + + + + + + + + + +

The name of the mailbox to create.

parentId + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The id of the parent of the mailbox to create.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to a Mailbox.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

destroyMailbox(id) → {Promise}

+ + + + + +
+

Destroy the Mailbox related to the given id on the server.
+This will issue a Client#destroyMailboxes request under the hoods, passing [id] option.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + +

The id of the mailbox to destroy.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to nothing if the Mailbox was destroyed successfully.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

destroyMailboxes(ids) → {Promise}

+ + + + + +
+

Destroy multiple Mailboxes specified to the given ids on the server.
+This will issue a Client#setMailboxes JMAP request under the hoods, passing the correct options.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ids + + +Array.<String> + + + +

An array IDs of the mailboxes to destroy. These IDs must be in the right order: Destroy X comes before destroy Y if X is a descendent of Y.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to nothing if all Mailboxes were destroyed successfully. Otherwise, it rejects error message of the first notDestroyed mailbox.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

destroyMessage(id) → {Promise}

+ + + + + +
+

Destroy the Message related to the given id on the server.
+This will issue a Client#setMessages JMAP request under the hoods, passing the correct options.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + +

The id of the object to destroy.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to nothing if the Message was destroyed successfully.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

destroyMessages(ids) → {Promise}

+ + + + + +
+

Destroy several Messages at once.
+This will issue a Client#setMessages JMAP request under the hoods, passing the correct options.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
ids + + +Array.<String> + + + +

The list of ids of the messages to destroy.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that resolves to a SetResponse, containing the result of the operation.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

getAccounts(optionsopt) → {Promise}

+ + + + + +
+

Sends a getAccounts JMAP request.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
options + + +Object + + + + + + <optional>
+ + + + + +
+ + null + +

The options to the getAccounts JMAP request.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to an array of Account objects.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

getMailboxes(optionsopt) → {Promise}

+ + + + + +
+

Sends a getMailboxes JMAP request.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
options + + +Object + + + + + + <optional>
+ + + + + +
+ + null + +

The options to the getMailboxes JMAP request.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to an array of Mailbox objects.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

getMailboxWithRole(role, optionsopt) → {Promise}

+ + + + + +
+

Finds a Mailbox with the given role.
+This will issue a getMailboxes JMAP request and search for the mailbox in the returned list.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
role + + +MailboxRole +| + +String + + + + + + + + + + + +

The desired mailbox role.

options + + +Object + + + + + + <optional>
+ + + + + +
+ + null + +

The options to the implicit getMailboxes JMAP request.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to the Mailbox if found.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

getMessageList(optionsopt) → {Promise}

+ + + + + +
+

Sends a getMessageList JMAP request.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
options + + +Object + + + + + + <optional>
+ + + + + +
+ + null + +

The options to the getMessageList JMAP request.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to a MessageList object.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

getMessages(optionsopt) → {Promise}

+ + + + + +
+

Sends a getMessages JMAP request.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
options + + +Object + + + + + + <optional>
+ + + + + +
+ + null + +

The options to the getMessages JMAP request.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to an array of Message objects.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

getThreads(optionsopt) → {Promise}

+ + + + + +
+

Sends a getThreads JMAP request.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
options + + +Object + + + + + + <optional>
+ + + + + +
+ + null + +

The options to the getThreads JMAP request.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to an array of Thread objects.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

getVacationResponse(optionsopt) → {Promise}

+ + + + + +
+

Gets the singleton VacationResponse instance for a given account.
+This will send a getVacationResponse request to the JMAP backend.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
options + + +Object + + + + + + <optional>
+ + + + + +

The options to the underlying getVacationResponse JMAP request.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
accountId + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The account ID to get the vacation response for. If null, the primary account is used.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to the VacationResponse instance.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

moveMessage(id, mailboxIds) → {Promise}

+ + + + + +
+

Moves a Message to a different set of mailboxes.
+This will issue a Client#setMessages JMAP request under the hoods, passing the correct options.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + +

The id of the Message to move.

mailboxIds + + +Array.<String> + + + +

The identifiers of the target mailboxes for the message.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to nothing if the message was moved successfully.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

saveAsDraft(message) → {Promise}

+ + + + + +
+

Save a message as draft by sending a setMessages JMAP request.
+The mailboxIds and isDraft properties of the given message will be overridden by this method.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
message + + +OutboundMessage + + + +

The message to save.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to a CreateMessageAck.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

send(message, outbox) → {Promise}

+ + + + + +
+

Sends a message by issuing a setMessages JMAP request.
+The mailboxIds and isDraft properties of the given message will be overridden by this method.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
message + + +OutboundMessage + + + +

The message to send.

outbox + + +Mailbox + + + +

The Mailbox with role='outbox', if already available

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to a CreateMessageAck.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

setFilter(filterRules, optionsopt) → {Promise}

+ + + + + +
+

Sets the singleton FilterRule instance for a given account.
+This will send a setFilter request to the JMAP backend.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
filterRules + + +Array.<FilterRule> +| + +Array.<Object> + + + + + + + + + +

The list of filter rules to set

options + + +Object + + + + + + <optional>
+ + + + + +

The options to the underlying setFilter JMAP request.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
accountId + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The account ID to set the filtering rules for. If null, the primary account is used.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to nothing upon success.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

setMailboxes(optionsopt) → {Promise}

+ + + + + +
+

Sends a setMailboxes JMAP request.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
options + + +Object + + + + + + <optional>
+ + + + + +
+ + null + +

The options to the setMailboxes JMAP request.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to a Mailbox object.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

setMessages(optionsopt) → {Promise}

+ + + + + +
+

Sends a setMessages JMAP request.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
options + + +Object + + + + + + <optional>
+ + + + + +
+ + null + +

The options to the setMessages JMAP request.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to a SetResponse object.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

setVacationResponse(vacationResponse, optionsopt) → {Promise}

+ + + + + +
+

Sets the singleton VacationResponse instance for a given account.
+This will send a setVacationResponse request to the JMAP backend.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
vacationResponse + + +VacationResponse + + + + + + + + + +

The VacationResponse instance to set

options + + +Object + + + + + + <optional>
+ + + + + +

The options to the underlying setVacationResponse JMAP request.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
accountId + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The account ID to set the vacation response for. If null, the primary account is used.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to nothing upon success.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

updateMailbox(id, options) → {Promise}

+ + + + + +
+

Updates properties of a Mailbox.
+This will issue a Client#setMailboxes JMAP request under the hoods, passing the correct options.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + +

The id of the Mailbox to update.

options + + +Object + + + +

The options of the target mailbox to be updated.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to nothing if the mailbox was updated successfully.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

updateMessage(id, options) → {Promise}

+ + + + + +
+

Updates properties of a Message.
+This will issue a Client#setMessages JMAP request under the hoods, passing the correct options.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + +

The id of the Message to update.

options + + +Object + + + +

The options of the target message to be updated.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
mailboxIds + + +Array.<String> + + + +

The identifiers of the new mailboxes for the message.

isFlagged + + +Boolean + + + +

This corresponds whether the message is flagged or not

isUnread + + +Boolean + + + +

This corresponds whether the message has been yet read or not

isAnswered + + +Boolean + + + +

This corresponds whether the message has been yet replied or not

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise that eventually resolves to nothing if the message was updated successfully.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

withAPIUrl(url) → {Client}

+ + + + + +
+

Sets the API URL of the target JMAP server. All JMAP requests will be sent to this URL.
+
+The URL will be exposed as the apiUrl property afterwards.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
url + + +String + + + +

The API URL of the JMAP server.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

This Client instance.

+
+ + + +
+
+ Type +
+
+ +Client + + +
+
+ + + + + + + + + + +

withAuthAccess(access) → {Client}

+ + + + + +
+

Initializes the client with an AuthAccess model from an authentication response.
+
+The individual properties of the AuthAccess object will be copied into client properties.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
access + + +AuthAccess +| + +Object + + + +

The response object from an authenticate process.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

This Client instance.

+
+ + + +
+
+ Type +
+
+ +Client + + +
+
+ + + + + + + + + + +

withAuthenticationToken(token, schemeopt) → {Client}

+ + + + + +
+

Registers an authentication token, obtained by an external mechanism from the target JMAP server.
+This token will then be used as the Authorization header, as per http://jmap.io/spec.html#authenticating-http-requests.
+
+The token will be exposed as the authToken property afterwards.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
token + + +String + + + + + + + + + +

The authentication token to use in JMAP requests.

scheme + + +String + + + + + + <optional>
+ + + + + +

The authentication scheme according to RFC 7235

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

This Client instance.

+
+ + + +
+
+ Type +
+
+ +Client + + +
+
+ + + + + + + + + + +

withAuthenticationUrl(url) → {Client}

+ + + + + +
+

Registers an authentication URL, that will be used as the endpoint to send authentication requests to the server.
+
+The URL will be exposed as the authenticationUrl property afterwards.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
url + + +String + + + +

The authentication url to use in JMAP requests.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

This Client instance.

+
+ + + +
+
+ Type +
+
+ +Client + + +
+
+ + + + + + + + + + +

withDownloadUrl(url) → {Client}

+ + + + + +
+

Sets the download URL, i.e.: the URL used to download attachments to Messages.
+
+The URL will be exposed as the downloadUrl property afterwards.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
url + + +String + + + +

The download URL of the JMAP server.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

This Client instance.

+
+ + + +
+
+ Type +
+
+ +Client + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/CreateMessageAck.html b/doc/api/CreateMessageAck.html new file mode 100644 index 0000000..e0853d4 --- /dev/null +++ b/doc/api/CreateMessageAck.html @@ -0,0 +1,430 @@ + + + + + JSDoc: Class: CreateMessageAck + + + + + + + + + + +
+ +

Class: CreateMessageAck

+ + + + + + +
+ +
+ +

CreateMessageAck

+ + +
+ +
+
+ + + + + +

new CreateMessageAck(jmap, response)

+ + + + + +
+

This class should be used to wrap a create response item from a setMessages request.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance that created this OutboundMessage.

response + + +Object + + + +

The raw created response object.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
blobId + + +String + + + + + + + + + + + +

The server side generated blobId of the created message.

size + + +Number + + + + + + + + + + + +

The server side size of the created message.

id + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The server side generated message id of the created message.

threadId + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The server side assigned threadId of the created message.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/EMailer.html b/doc/api/EMailer.html new file mode 100644 index 0000000..2e0d5fd --- /dev/null +++ b/doc/api/EMailer.html @@ -0,0 +1,612 @@ + + + + + JSDoc: Class: EMailer + + + + + + + + + + +
+ +

Class: EMailer

+ + + + + + +
+ +
+ +

EMailer

+ + +
+ +
+
+ + + + + +

new EMailer(optsopt)

+ + + + + +
+

This class represents a JMAP EMailer.
+An EMailer object holds the name and email address of either a sender or a recipient of a Message.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this EMailer.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
name + + +String + + + + + + <optional>
+ + + + + +
+ + '' + +

The name of the emailer.

email + + +String + + + + + + <optional>
+ + + + + +
+ + '@' + +

The email address of the emailer.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) fromJSONObject(jmap, object) → {EMailer}

+ + + + + +
+

Creates a EMailer from its JSON representation.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance that originates the EMailer instance. Is actually ignored.

object + + +Object + + + +

The JSON representation of the EMailer, as a Javascript object

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +EMailer + + +
+
+ + + + + + + + + + +

(static) unknown() → {EMailer}

+ + + + + +
+

This method returns the unknown EMailer, that is, an EMailer instance with all fields set to defaults.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

The unknown EMailer.

+
+ + + +
+
+ Type +
+
+ +EMailer + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/ES6PromiseProvider.html b/doc/api/ES6PromiseProvider.html new file mode 100644 index 0000000..b89666d --- /dev/null +++ b/doc/api/ES6PromiseProvider.html @@ -0,0 +1,170 @@ + + + + + JSDoc: Class: ES6PromiseProvider + + + + + + + + + + +
+ +

Class: ES6PromiseProvider

+ + + + + + +
+ +
+ +

ES6PromiseProvider

+ + +
+ +
+
+ + + + + +

new ES6PromiseProvider()

+ + + + + +
+

A PromiseProvider implementation creating native ES6 Promises.
+This class supposes that the Promise class is available.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/FilterRule.html b/doc/api/FilterRule.html new file mode 100644 index 0000000..b163692 --- /dev/null +++ b/doc/api/FilterRule.html @@ -0,0 +1,268 @@ + + + + + JSDoc: Class: FilterRule + + + + + + + + + + +
+ +

Class: FilterRule

+ + + + + + +
+ +
+ +

FilterRule

+ + +
+ +
+
+ + + + + +

new FilterRule(jmap, name)

+ + + + + +
+

This class represents a JMAP FilterRule.
+The FilterRule object represents the state of incoming message filtering for an account.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance that created this FilterRule.

name + + +String + + + +

The name of the rule

+

NOTE: How to use and extend this model ? + FilterRule is conceived so that a rule can be specified in a highly didactic way. For instance:

+
 new jmap.FilterRule(client, 'My filter')
+   .when.from
+     .value('admin@open-paas.org')
+     .comparator(jmap.FilterRule.Comparator.EXACTLY_EQUALS)
+   .then.moveTo
+     .mailboxId('36e4d1c0-a473-11e8-aa26-bfb5d32a28f6');

To achive this, it uses the builder design pattern. To extend this model with new actions and conditions, + you just need to create a new class that extends AbstractConditionAction and implements + AbstractConditionAction#_init and AbstractConditionAction#_toJSONObject.

+

AbstractConditionAction#_init is called by AbstractConditionAction' constructor and + AbstractConditionAction#_toJSONObject is used to generate a JSON representation of the object. + Then, just provide any useful property.

+

To make the new condition or action available to the builder, you need to extend FilterRuleCondition + (if defining a new condition) or FilterRuleAction (if defining a new action)

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/JQueryTransport.html b/doc/api/JQueryTransport.html new file mode 100644 index 0000000..41a9be3 --- /dev/null +++ b/doc/api/JQueryTransport.html @@ -0,0 +1,239 @@ + + + + + JSDoc: Class: JQueryTransport + + + + + + + + + + +
+ +

Class: JQueryTransport

+ + + + + + +
+ +
+ +

JQueryTransport

+ + +
+ +
+
+ + + + + +

new JQueryTransport(promiseProvideropt)

+ + + + + +
+

A Transport implementation for jQuery.
+This class supposes that the jQuery global object is available.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
promiseProvider + + +PromiseProvider + + + + + + <optional>
+ + + + + +
+ + null + +

A PromiseProvider implementation.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/JSONBuilder.html b/doc/api/JSONBuilder.html new file mode 100644 index 0000000..9adddc7 --- /dev/null +++ b/doc/api/JSONBuilder.html @@ -0,0 +1,1138 @@ + + + + + JSDoc: Class: JSONBuilder + + + + + + + + + + +
+ +

Class: JSONBuilder

+ + + + + + +
+ +
+ +

JSONBuilder

+ + +
+ +
+
+ + + + + +

new JSONBuilder()

+ + + + + +
+

This class helps to create JSON representation from a model. +Usage:

+
  return new JSONBuilder()
+    .appendIfDefined('inReplyToMessageId', this.inReplyToMessageId)
+    .appendIfDefined('isUnread', this.isUnread)
+    .appendIfDefined('isFlagged', this.isFlagged)
+    .build();
+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

append(name, value)

+ + + + + +
+

Will append the value to the building object, using the name as key.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + +

The name to use as key.

value + + +* + + + +

The value to append.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

this builder

+
+ + + + + + + + + + + + +

appendDateIfDefined(name, dateopt)

+ + + + + +
+

If defined, it will append date to the building object as an ISO Date String, using name as the key.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
name + + +String + + + + + + + + + +

The name to use as key.

date + + +Date + + + + + + <optional>
+ + + + + +

The Date to append.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

This JSONBuilder instance

+
+ + + + + + + + + + + + +

appendIfDefined(name, valueopt)

+ + + + + +
+

If defined, it will append the value to the building object, using the name as key.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
name + + +String + + + + + + + + + +

The name to use as key.

value + + +* + + + + + + <optional>
+ + + + + +

The value to append.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

this builder

+
+ + + + + + + + + + + + +

appendIfNotEmpty(name, valueopt)

+ + + + + +
+

If defined and not empty, it will append the value array to the building object, using the name as key.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
name + + +String + + + + + + + + + +

The name to use as key.

value + + +Array + + + + + + <optional>
+ + + + + +

The value to append.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

this builder

+
+ + + + + + + + + + + + +

appendObject(name, value)

+ + + + + +
+

Will append the value object to the building object by recursively calling toJSONObject() +on each child if an object.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
name + + +String + + + +

The name to use as key.

value + + +Array + + + +

The Object to append

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +

build()

+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

an object with all appended values

+
+ + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/JmapError.html b/doc/api/JmapError.html new file mode 100644 index 0000000..39bfff1 --- /dev/null +++ b/doc/api/JmapError.html @@ -0,0 +1,490 @@ + + + + + JSDoc: Class: JmapError + + + + + + + + + + +
+ +

Class: JmapError

+ + + + + + +
+ +
+ +

JmapError

+ + +
+ +
+
+ + + + + +

new JmapError(payload, methodopt)

+ + + + + +
+

A JmapError is a custom Error thrown when a request is rejected by the JMAP backend.
+The type property holds the type of error that happened. Refer to the JMAP spec +for details on the available errors.
+Other properties may be present with further information; these are detailed in the method descriptions where appropriate.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
payload + + +Object + + + + + + + + + + + +

The error payload, from which detailed information about the error can be retrieved.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
type + + +String + + + + + + <optional>
+ + + + + +
+ +

The type of this JmapError.

description + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The description, if any, of this JmapError.

+ +
method + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The JMAP method that triggered this JmapError.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+
    +
  • Error
  • +
+
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

toString() → {String}

+ + + + + +
+

Returns a String representation of this JmapError.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

The human-readable representation of this JmapError.

+
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/MailCapabilities.html b/doc/api/MailCapabilities.html new file mode 100644 index 0000000..e9f5484 --- /dev/null +++ b/doc/api/MailCapabilities.html @@ -0,0 +1,458 @@ + + + + + JSDoc: Class: MailCapabilities + + + + + + + + + + +
+ +

Class: MailCapabilities

+ + + + + + +
+ +
+ +

MailCapabilities

+ + +
+ +
+
+ + + + + +

new MailCapabilities(optsopt)

+ + + + + +
+

This class represents a JMAP MailCapabilities.
+An MailCapabilities object describes mail-related capabilities of a JMAP server.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this MailCapabilities.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
maxMailboxesPerMessage + + +Number + + + + + + <optional>
+ + + + + +
+ + null + +

The maximum number of mailboxes that can be can assigned to a single message.

maxSizeMessageAttachments + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The maximum total size of attachments, in bytes, allowed for messages.

maxDelayedSend + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The number in seconds of the maximum delay the server supports in sending. 0 if delayed send is not supported.

messageListSortOptions + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

A list of all the message properties the server supports for sorting by.

submissionExtensions= + + + + + + + + + +

{String[String[]]} Known safe-to-expose EHLO capabilities of the submission server.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/Mailbox.html b/doc/api/Mailbox.html new file mode 100644 index 0000000..4098972 --- /dev/null +++ b/doc/api/Mailbox.html @@ -0,0 +1,1810 @@ + + + + + JSDoc: Class: Mailbox + + + + + + + + + + +
+ +

Class: Mailbox

+ + + + + + +
+ +
+ +

Mailbox

+ + +
+ +
+
+ + + + + +

new Mailbox(jmap, id, name, optsopt)

+ + + + + +
+

This class represents a JMAP Mailbox.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
jmap + + +Client + + + + + + + + + +

The Client instance that created this Mailbox.

id + + +String + + + + + + + + + +

The unique identifier of this Mailbox.

name + + +String + + + + + + + + + +

The user-visible name (i.e.: display name) of this Mailbox.

opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this Mailbox.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
namespace= + + + + <optional>
+ + + + + +
+ +

{Object} The namespace give information about mailbox type and owner.

parentId + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The Mailbox id for the parent of this mailbox, or null if this mailbox is at the top level.

role + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The role of this mailbox, if it is a system mailbox. See the specification for the possible values.

sharedWith= + + + + <optional>
+ + + + + +
+ +

{Object} The sharedWith give information about mailbox shared and rights.

sortOrder + + +String + + + + + + <optional>
+ + + + + +
+ + 0 + +

Defines the sort order of mailboxes when presented in the UI.

mustBeOnlyMailbox + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

If true, messages in this mailbox may not also be in any other mailbox.

mayReadItems + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

If true, may use this mailbox as part of a filter in a Client#getMessageList call.

mayAddItems + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

If true, the user may add messages to this mailbox.

mayRemoveItems + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

If true, the user may remove messages from this mailbox.

mayCreateChild + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

If true, the user may create a Mailbox with this Mailbox as its parent.

mayRename + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

If true, the user may rename this mailbox or make it a child of another mailbox.

mayDelete + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

If true, the user may delete this mailbox.

totalMessages + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The number of messages in this mailbox.

unreadMessages + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The number of messages in this mailbox with isUnread=true and isDraft=false.

totalThreads + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The number of threads where at least one message in the thread is in this mailbox.

unreadThreads + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The number of threads where at least one message in the thread is in this mailbox with isUnread=true and isDraft=false.

quotas= + + + + <optional>
+ + + + + +
+ +

{Object} List of enforced quotas. 'STORAGE' for size quota and 'MESSAGE' for messages count. Each one provide used and max properties. + used (Number) number of messages, or size in bytes for storage + max (Number|null) maximum number of messages, or maximum size in bytes for storage. Null means unlimited

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) fromJSONObject(jmap, object) → {Mailbox}

+ + + + + +
+

Creates a Mailbox from its JSON representation.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance passed to the Mailbox constructor.

object + + +Object + + + +

The JSON representation of the Mailbox, as a Javascript object.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + +

The identifier of the Mailbox.

name + + +String + + + +

The user-visible name of the Mailbox.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Mailbox + + +
+
+ + + + + + + + + + +

destroy() → {Promise}

+ + + + + +
+

Destroy this Mailbox on the server.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.destroyMailbox.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

getMessageList(optionsopt) → {Promise}

+ + + + + +
+

Fetches a message list from this Mailbox.
+This will delegate to Client#getMessageList, passing the following filter:

+
{
+  inMailboxes: [<this Mailbox id>]
+}
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
options + + +Object + + + + + + <optional>
+ + + + + +

The options object passed to Client#getMessageList. + Please note that the filter option will be overriden if defined.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A promise that eventually resolves with a MessageList instance.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

update(options) → {Promise}

+ + + + + +
+

Update this Mailbox.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
options + + +Object + + + +

The attribute to be updated in this Mailbox.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
name + + +String + + + + + + + + + + + +

The user-visible name of the Mailbox.

parentId + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The Mailbox id for the parent of this mailbox, or null if this mailbox is at the top level.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.updateMailbox.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/MailboxRole.html b/doc/api/MailboxRole.html new file mode 100644 index 0000000..da6f112 --- /dev/null +++ b/doc/api/MailboxRole.html @@ -0,0 +1,373 @@ + + + + + JSDoc: Class: MailboxRole + + + + + + + + + + +
+ +

Class: MailboxRole

+ + + + + + +
+ +
+ +

MailboxRole

+ + +
+ +
+
+ + + + + +

new MailboxRole(role)

+ + + + + +
+

The MailboxRole class is simply a holder for predefined JMAP mailbox roles.
+It exposes class constants for every predefined roles (trash, inbox, etc.)

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
role + + +String + + + +

The JMAP mailbox role. This is exposed as the value property.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) fromRole(role) → {MailboxRole}

+ + + + + +
+

Returns the class constant mapping to the given JMAP role, or MailboxRole.UNKNOWN +if the role is undefined, null or isn't a predefined role.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
role + + +String + + + +

The JMAP role to find the MailboxRole for.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +MailboxRole + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/Message.html b/doc/api/Message.html new file mode 100644 index 0000000..27d9a0e --- /dev/null +++ b/doc/api/Message.html @@ -0,0 +1,2583 @@ + + + + + JSDoc: Class: Message + + + + + + + + + + +
+ +

Class: Message

+ + + + + + +
+ +
+ +

Message

+ + +
+ +
+
+ + + + + +

new Message(jmap, id, blobId, threadId, mailboxIds, optsopt)

+ + + + + +
+

This class represents a JMAP Message.
+When creating a new Message instance, the following requirements must be met:

+
    +
  • The threadId must be defined (in JMAP, a Message is always in a Thread)
  • +
  • The mailboxIds must contain at least one element.
  • +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
jmap + + +Client + + + + + + + + + +

The Client instance that created this Message.

id + + +String + + + + + + + + + +

The unique identifier of this Message.

blobId + + +String + + + + + + + + + +

The identifier representing the raw [@!RFC5322] message.

threadId + + +String + + + + + + + + + +

The unique identifier of the Thread this Message is in.

mailboxIds + + +Array.<String> + + + + + + + + + +

The array of Mailbox identifiers this Message is present into.

opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this Message.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
inReplyToMessageId + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The id of the Message this Message is a reply to.

isUnread + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

Has the message not yet been read? This maps to the opposite of the \Seen flag in IMAP.

isFlagged + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

Is the message flagged? This maps to the \Flagged flag in IMAP.

isAnswered + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

Has the message been replied to? This maps to the \Answered flag in IMAP.

isForwarded + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

Has the message been forwarded ?.

isDraft + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

Is the message a draft? This maps to the \Draft flag in IMAP.

hasAttachment + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

Does the message have any attachments?

headers + + +Object + + + + + + <optional>
+ + + + + +
+ +

A hash of header name to header value for all headers in the message. + For headers that occur multiple times, the values are concatenated with a single new line (\n) character in between each one.

from + + +EMailer + + + + + + <optional>
+ + + + + +
+ + null + +

The EMailer object representing the first identified sender of this Message.

to + + +Array.<EMailer> + + + + + + <optional>
+ + + + + +
+ + [EMailer.unknown] + +

The array of EMailer objects representing the To: of this Message.

cc + + +Array.<EMailer> + + + + + + <optional>
+ + + + + +
+ + [EMailer.unknown] + +

The array of EMailer objects representing the CC: of this Message.

bcc + + +Array.<EMailer> + + + + + + <optional>
+ + + + + +
+ + [EMailer.unknown] + +

The array of EMailer objects representing the BCC: of this Message.

replyTo + + +Array.<EMailer> + + + + + + <optional>
+ + + + + +
+ + EMailer.unknown + +

The array of EMailer objects representing the Reply-To: of this Message.

subject + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The subject of this Message.

date + + +Date + + + + + + <optional>
+ + + + + +
+ + null + +

The date the Message was sent (or saved, if the message is a draft).

size + + +String + + + + + + <optional>
+ + + + + +
+ + 0 + +

The size in bytes of the whole message as counted by the server.

preview + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

Up to 256 characters of the beginning of a plain text version of the Message body.

textBody + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The plain text body part for the Message.

htmlBody + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The HTML body part for the Message, if present.

attachments + + +Array.<Attachment> + + + + + + <optional>
+ + + + + +
+ + [] + +

An array of Attachment objects detailing all the attachments to the message.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) fromJSONObject(jmap, object) → {Message}

+ + + + + +
+

Creates a Message from its JSON representation.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance passed to the Message constructor.

object + + +Object + + + +

The JSON representation of the Message, as a Javascript object.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +Object + + + +

The identifier of the Message.

blobId + + +String + + + +

The identifier representing the raw [@!RFC5322] message.

threadId + + +String + + + +

The identifier of the thread the Message is in.

mailboxIds + + +Array.<String> + + + +

The array of Mailbox identifiers the Message is present into.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Message + + +
+
+ + + + + + + + + + +

destroy() → {Promise}

+ + + + + +
+

Destroy this Message on the server.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.destroyMessage.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

move(mailboxIds) → {Promise}

+ + + + + +
+

Moves this Message to a different set of mailboxes.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
mailboxIds + + +Array.<String> + + + +

The identifiers of the target mailboxes for the message.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.moveMessage.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

moveToMailboxWithRole(role) → {Promise}

+ + + + + +
+

Moves this Message to the mailbox holding the given role.
+This will first do a JMAP request to find the mailbox with the given role, then a Message#move to move the message.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
role + + +MailboxRole +| + +String + + + +

The desired mailbox role.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Message#move.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

setIsAnswered(isAnswered) → {Promise}

+ + + + + +
+

Updates the isAnswered field of this Message.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
isAnswered + + +Boolean + + + +

The isAnswered field of the message.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.updateMessage.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

setIsFlagged(isFlagged) → {Promise}

+ + + + + +
+

Updates the isFlagged field of this Message.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
isFlagged + + +Boolean + + + +

The isFlagged field of the message.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.updateMessage.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

setIsUnread(isUnread) → {Promise}

+ + + + + +
+

Updates the isUnread field of this Message.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
isUnread + + +Boolean + + + +

The isUnread field of the message.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.updateMessage.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

update(options) → {Promise}

+ + + + + +
+

Updates this Message.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
options + + +Object + + + +

The options to be updated in this Message as per Client.updateMessage.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.updateMessage.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/MessageList.html b/doc/api/MessageList.html new file mode 100644 index 0000000..c0b8125 --- /dev/null +++ b/doc/api/MessageList.html @@ -0,0 +1,1146 @@ + + + + + JSDoc: Class: MessageList + + + + + + + + + + +
+ +

Class: MessageList

+ + + + + + +
+ +
+ +

MessageList

+ + +
+ +
+
+ + + + + +

new MessageList(jmap, optsopt)

+ + + + + +
+

This class represents a JMAP MessageList.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
jmap + + +Client + + + + + + + + + +

The Client instance that created this Mailbox.

opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this Mailbox.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
accountId + + +String + + + + + + <optional>
+ + + + + +
+ + '' + +

The id of the Account used in the request that originated this MessageList.

filter + + +Object + + + + + + <optional>
+ + + + + +
+ + null + +

The filter used in the request that originated this MessageList.

sort + + +Object + + + + + + <optional>
+ + + + + +
+ + null + +

The sort properties used in the request that originated this MessageList.

collapseThreads + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

The collapseThreads value used in the request that originated this MessageList.

position + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The 0-based index of the first result in the threadIds array within the complete list.

total + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The total number of messages in the message list (given the filter and collapseThreads arguments).

threadIds + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

The list of Thread identifiers for each message in the list after filtering, sorting and collapsing threads.

messageIds + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

The list of Message identifiers for each message in the list after filtering, sorting and collapsing threads.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) fromJSONObject(jmap, object) → {MessageList}

+ + + + + +
+

Creates a MessageList from its JSON representation.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance passed to the MessageList constructor.

object + + +Object + + + +

The JSON representation of the MessageList, as a Javascript object.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +MessageList + + +
+
+ + + + + + + + + + +

getMessages(optionsopt) → {Promise}

+ + + + + +
+

Fetches all messages contained in this MessageList.
+This will delegate to Client#getMessages, passing this MessageList's messageIds as the ids option.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
options + + +Object + + + + + + <optional>
+ + + + + +

The options object passed to Client#getMessages. + Please note that the ids option will be overriden if defined.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A promise that eventually resolves with an array of Message instances.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

getThreads(optionsopt) → {Promise}

+ + + + + +
+

Fetches all threads contained in this MessageList.
+This will delegate to Client#getThreads, passing this MessageList's threadIds as the ids option.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
options + + +Object + + + + + + <optional>
+ + + + + +

The options object passed to Client#getThreads. + Please note that the ids option will be overriden if defined.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A promise that eventually resolves with an array of Thread instances.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/Model.html b/doc/api/Model.html new file mode 100644 index 0000000..f12dcf7 --- /dev/null +++ b/doc/api/Model.html @@ -0,0 +1,214 @@ + + + + + JSDoc: Class: Model + + + + + + + + + + +
+ +

Class: Model

+ + + + + + +
+ +
+ +

Model

+ + +
+ +
+
+ + + + + +

(abstract) new Model(jmap)

+ + + + + +
+

The base class for all JMAP entities.
+When implementing new entities you should always try to inherit from this.
+
+You shouldn't use this constructor directly, but rather create instances of concrete implementations.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance that created this Model. This will be exposed as the _jmap property.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/OutboundMessage.html b/doc/api/OutboundMessage.html new file mode 100644 index 0000000..23aa8ba --- /dev/null +++ b/doc/api/OutboundMessage.html @@ -0,0 +1,1026 @@ + + + + + JSDoc: Class: OutboundMessage + + + + + + + + + + +
+ +

Class: OutboundMessage

+ + + + + + +
+ +
+ +

OutboundMessage

+ + +
+ +
+
+ + + + + +

new OutboundMessage(jmap, optsopt)

+ + + + + +
+

This class represents a JMAP Message but for client-to-server purpose.
+When creating a new OutboundMessage instance, the following requirements must be met:

+
    +
  • The id, blobId, threadId, size, preview, hasAttachment and attachedMessages must be not defined (it is set by the server upon creation)
  • +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
jmap + + +Client + + + + + + + + + +

The Client instance that created this OutboundMessage.

opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this OutboundMessage.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
mailboxIds + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

The array of Mailbox identifiers which will contain this OutboundMessage.

inReplyToMessageId + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The id of the Message this OutboundMessage is a reply to.

isUnread + + +Boolean + + + + + + <optional>
+ + + + + +
+ + null + +

Has the message not yet been read? This maps to the opposite of the \Seen flag in IMAP.

isFlagged + + +Boolean + + + + + + <optional>
+ + + + + +
+ + null + +

Is the message flagged? This maps to the \Flagged flag in IMAP.

isAnswered + + +Boolean + + + + + + <optional>
+ + + + + +
+ + null + +

Has the message been replied to? This maps to the \Answered flag in IMAP.

isDraft + + +Boolean + + + + + + <optional>
+ + + + + +
+ + null + +

Is the message a draft? This maps to the \Draft flag in IMAP.

headers + + +Object + + + + + + <optional>
+ + + + + +
+ +

A hash of header name to header value for all headers in the message. + For headers that occur multiple times, the values are concatenated with a single new line (\n) character in between each one.

from + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

Overrides the value used as From: in the headers.

to + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + null + +

Overrides the value used as To: in the headers.

cc + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + null + +

Overrides the value used as CC: in the headers.

bcc + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + null + +

Overrides the value used as BCC: in the headers.

replyTo + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

Overrides the value used as Reply-To: in the headers.

subject + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The subject of this OutboundMessage.

textBody + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The plain text body part.

htmlBody + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The HTML body part.

attachments + + +Array.<Attachment> + + + + + + <optional>
+ + + + + +
+ + [] + +

An array of Attachment objects detailing all the attachments to the message. + Attachments must first be uploaded using the standard upload mechanism.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

toJSONObject()

+ + + + + +
+

Creates a JSON representation from this model.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

JSON object with only owned properties and non default values.

+
+ + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/PromiseProvider.html b/doc/api/PromiseProvider.html new file mode 100644 index 0000000..b36763f --- /dev/null +++ b/doc/api/PromiseProvider.html @@ -0,0 +1,336 @@ + + + + + JSDoc: Class: PromiseProvider + + + + + + + + + + +
+ +

Class: PromiseProvider

+ + + + + + +
+ +
+ +

PromiseProvider

+ + +
+ +
+
+ + + + + +

(abstract) new PromiseProvider()

+ + + + + +
+

The PromiseProvider class is the base class for providers of Promise instances.
+A concrete implementation is required to implement PromiseProvider#newPromise so that this method +returns a Promise that will be used by the library to do JMAP requests and other asynchronous things.
+
+This level of abstraction allows users of the library to plug in their own implementation in order to use their +favorite Promise library. Implementations for Q +and native ES6 Promises are provided.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(abstract) newPromise(resolver) → {Promise}

+ + + + + +
+

This method must be implemented by concrete PromiseProvider implementations in such a way that:

+
    +
  • A Promise is created from the resolver argument and is returned.
  • +
  • The Promise will be fulfilled when the resolve function of the resolver is called.
  • +
  • The Promise will be rejected when the reject function of the resolver is called.
  • +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
resolver + + +function + + + +

A Function with two arguments resolve and reject, both functions. + The first argument fulfills the promise, the second argument rejects it.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/QPromiseProvider.html b/doc/api/QPromiseProvider.html new file mode 100644 index 0000000..d258168 --- /dev/null +++ b/doc/api/QPromiseProvider.html @@ -0,0 +1,170 @@ + + + + + JSDoc: Class: QPromiseProvider + + + + + + + + + + +
+ +

Class: QPromiseProvider

+ + + + + + +
+ +
+ +

QPromiseProvider

+ + +
+ +
+
+ + + + + +

new QPromiseProvider()

+ + + + + +
+

A PromiseProvider implementation creating Q promises.
+This class requires Q to be installed as dependency.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/RequestTransport.html b/doc/api/RequestTransport.html new file mode 100644 index 0000000..c9be11f --- /dev/null +++ b/doc/api/RequestTransport.html @@ -0,0 +1,239 @@ + + + + + JSDoc: Class: RequestTransport + + + + + + + + + + +
+ +

Class: RequestTransport

+ + + + + + +
+ +
+ +

RequestTransport

+ + +
+ +
+
+ + + + + +

new RequestTransport(promiseProvideropt)

+ + + + + +
+

A Transport implementation for Request.
+This class requires request to be installed as dependency.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
promiseProvider + + +PromiseProvider + + + + + + <optional>
+ + + + + +
+ + null + +

A PromiseProvider implementation.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/ServerCapabilities.html b/doc/api/ServerCapabilities.html new file mode 100644 index 0000000..9fdc512 --- /dev/null +++ b/doc/api/ServerCapabilities.html @@ -0,0 +1,527 @@ + + + + + JSDoc: Class: ServerCapabilities + + + + + + + + + + +
+ +

Class: ServerCapabilities

+ + + + + + +
+ +
+ +

ServerCapabilities

+ + +
+ +
+
+ + + + + +

new ServerCapabilities(optsopt)

+ + + + + +
+

This class represents a JMAP ServerCapabilities.
+An ServerCapabilities object describes general capabilities of a JMAP server.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this ServerCapabilities.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
maxSizeUpload + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The maximum file size, in bytes, that the server will accept for a single file upload.

maxSizeRequest + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The maximum size, in bytes, that the server will accept for a single request to the API endpoint.

maxConcurrentUpload + + +Number + + + + + + <optional>
+ + + + + +
+ + 1 + +

The maximum number of concurrent requests the server will accept to the upload endpoint.

maxConcurrentRequests + + +Number + + + + + + <optional>
+ + + + + +
+ + 1 + +

The maximum number of concurrent requests the server will accept to the API endpoint.

maxCallsInRequest + + +Number + + + + + + <optional>
+ + + + + +
+ + 1 + +

The maximum number of method calls the server will accept in a single request to the API endpoint.

maxObjectsInGet + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The maximum number of objects that the client may request in a single getXXX type method call.

maxObjectsInSet + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The maximum number of objects the client may send to create, update or destroy in a single setXXX type method call.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/SetResponse.html b/doc/api/SetResponse.html new file mode 100644 index 0000000..f44e53a --- /dev/null +++ b/doc/api/SetResponse.html @@ -0,0 +1,905 @@ + + + + + JSDoc: Class: SetResponse + + + + + + + + + + +
+ +

Class: SetResponse

+ + + + + + +
+ +
+ +

SetResponse

+ + +
+ +
+
+ + + + + +

new SetResponse(jmap, optsopt)

+ + + + + +
+

This class represents a JMAP [xxxSet] http://jmap.io/spec.html#setfoos.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
jmap + + +Client + + + + + + + + + +

The Client instance that created this SetResponse.

opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this SetResponse.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
accountId + + +String + + + + + + <optional>
+ + + + + +
+ + '' + +

The id of the Account used in the request that originated this SetResponse.

oldState + + +String + + + + + + <optional>
+ + + + + +
+ + '' + +

The state string that would have been returned by getXXX before making the requested changes, + or null if the server doesn’t know what the previous state string was.

newState + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + '' + +

The state string that will now be returned by getXXX.

created + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

A map of the creation id to an object containing any server-assigned properties of + the XXX object (including the id) for all successfully created records.

updated + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

A list of XXX ids for records that were successfully updated.

destroyed + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

A list of XXX ids for records that were successfully destroyed.

MDNSent + + +Array.<String> +| + +null + + + + + + <optional>
+ + + + + +
+ + [] + +

A list of receipt request ids for receipt that were successfully sent.

notCreated + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

A map of creation id to a SetError object for each XXX that failed to be created.

notUpdated + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

A map of XXX id to a SetError object for each XXX that failed to be updated.

notDestroyed + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

A map of XXX id to a SetError object for each XXX that failed to be destroyed.

MDNNotSent= + + + + <optional>
+ + + + + +
+ +

{String[SetError]|null} A map of MDN request id to a SetError object for each receipt that failed to be sent, or null if all successful.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) fromJSONObject(jmap, object) → {SetResponse}

+ + + + + +
+

Creates a SetResponse from its JSON representation.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance passed to the SetResponse constructor.

object + + +Object + + + +

The JSON representation of the SetResponse, as a Javascript object.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +SetResponse + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/Thread.html b/doc/api/Thread.html new file mode 100644 index 0000000..ec419ea --- /dev/null +++ b/doc/api/Thread.html @@ -0,0 +1,1531 @@ + + + + + JSDoc: Class: Thread + + + + + + + + + + +
+ +

Class: Thread

+ + + + + + +
+ +
+ +

Thread

+ + +
+ +
+
+ + + + + +

new Thread(jmap, id, optsopt)

+ + + + + +
+

This class represents a JMAP Thread.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
jmap + + +Client + + + + + + + + + +

The Client instance that created this Thread.

id + + +String + + + + + + + + + +

The unique identifier of this Thread.

opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this Thread.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
messageIds + + +Array.<String> + + + + + + <optional>
+ + + + + +
+ + [] + +

An array of message identifiers contained in this Thread.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) fromJSONObject(jmap, object) → {Thread}

+ + + + + +
+

Creates a Thread from its JSON representation.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance passed to the Thread constructor.

object + + +Object + + + +

The JSON representation of the Thread, as a Javascript object.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
id + + +String + + + +

The identifier of the Thread.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Thread + + +
+
+ + + + + + + + + + +

destroy() → {Promise}

+ + + + + +
+

Destroy this Thread on the server.
+This will internally destory all messages contained in this thread.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.destroyMessages.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

getMessages(optionsopt) → {Promise}

+ + + + + +
+

Fetches all messages contained in this Thread.
+This will delegate to Client#getMessages, passing this Thread's messageIds as the ids option.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
options + + +Object + + + + + + <optional>
+ + + + + +

The options object passed to Client#getMessages. + Please note that the ids option will be overriden if defined.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A promise that eventually resolves with an array of Message instances.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

move(mailboxIds) → {Promise}

+ + + + + +
+

Moves this Thread to a different set of mailboxes.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
mailboxIds + + +Array.<String> + + + +

The identifiers of the target mailboxes for the thread.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.setMessages.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

moveToMailboxWithRole(role) → {Promise}

+ + + + + +
+

Moves this Thread to the mailbox holding the given role.
+This will first do a JMAP request to find the mailbox with the given role, then a Thread#move to move the message.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
role + + +MailboxRole +| + +String + + + +

The desired mailbox role.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Thread#move.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

setIsFlagged(isFlagged) → {Promise}

+ + + + + +
+

Updates the isFlagged field of all Messages of this Thread.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
isFlagged + + +Boolean + + + +

The isFlagged field of the thread.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.setMessages.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + +

setIsUnread(isUnread) → {Promise}

+ + + + + +
+

Updates the isUnread field of this Message.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
isUnread + + +Boolean + + + +

The isUnread field of the thread.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

A Promise, as per Client.setMessages.

+
+ + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/Transport.html b/doc/api/Transport.html new file mode 100644 index 0000000..c3a0eb6 --- /dev/null +++ b/doc/api/Transport.html @@ -0,0 +1,412 @@ + + + + + JSDoc: Class: Transport + + + + + + + + + + +
+ +

Class: Transport

+ + + + + + +
+ +
+ +

Transport

+ + +
+ +
+
+ + + + + +

(abstract) new Transport()

+ + + + + +
+

The Transport class is the base class for providers of a HTTP transport layer.
+A concrete implementation is required to implement Transport#post so that this method returns a +Promise that will be resolved or rejected depending on the result of the underlying HTTP request
+To create Promise instances, a Transport implementation should use a PromiseProvider. +Client instances will automatically provide transports with the configured PromiseProvider as the +promiseProvider property. +
+This level of abstraction allows users of the library to plug in their own implementation in order to use their +favorite HTTP transport library. Implementations for Request +and jQuery are provided.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(abstract) post(url, headers, data, raw) → {Promise}

+ + + + + +
+

This method must be implemented by concrete Transport implementations in such a way that:

+
    +
  • A HTTP POST request is made on url with the given headers and data (i.e.: payload)
  • +
  • A Promise is returned (this.promiseProvider will be available to create Promise instances)
  • +
  • The Promise is fulfilled when the HTTP request returns 200 (http://jmap.io/spec.html#jmap-over-https)
  • +
  • The Promise is rejected if the HTTP request fails, or if the return status code is not 200
  • +
  • When the Promise is fulfilled, the raw JMAP response is returned
  • +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
url + + +String + + + +

The URL to POST to

headers + + +Object + + + +

A hash of header names to header values that must be transmitted as part of the request

data + + +* + + + +

The request payload, as a Javascript object. It's the responsibility of the Transport implementation + to serialize the data as a JSON String whenever required.

raw + + +Boolean + + + +

Whether the requests sends and expects raw (plain text) data instead of the default JSON.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise + + +
+
+ + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/TransportError.html b/doc/api/TransportError.html new file mode 100644 index 0000000..5ea1f5d --- /dev/null +++ b/doc/api/TransportError.html @@ -0,0 +1,319 @@ + + + + + JSDoc: Class: TransportError + + + + + + + + + + +
+ +

Class: TransportError

+ + + + + + +
+ +
+ +

TransportError

+ + +
+ +
+
+ + + + + +

new TransportError(causeopt, statusCodeopt, responseTextopt)

+ + + + + +
+

A TransportError is a custom Error thrown when a request to a remote server fails.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
cause + + +* + + + + + + <optional>
+ + + + + +
+ + null + +

The underlying cause of this TransportError. Though this is usually an Error, this + might actually be anything and depends on the chosen Transport implementation.

statusCode + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The HTTP status code sent by the server, if the request reached the server.

responseText + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The HTTP response sent by the server, if any.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/Utils.html b/doc/api/Utils.html new file mode 100644 index 0000000..135d615 --- /dev/null +++ b/doc/api/Utils.html @@ -0,0 +1,2330 @@ + + + + + JSDoc: Class: Utils + + + + + + + + + + +
+ +

Class: Utils

+ + + + + + +
+ +
+ +

Utils

+ + +
+ +
+
+ + + + + +

new Utils()

+ + + + + +
+

This class contains some useful utility methods.
+The Utils class cannot be instantiated (its constructor will throw if called), all its methods are static.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) appendQueryParameter(uri, key, value) → {String}

+ + + + + +
+

Appends a query parameter to an existing URL, taking care of existing query parameters.
+This method returns uri as-is if key or value is not defined.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
uri + + +String + + + +

The URI to modify.

key + + +String + + + +

The name of the parameter to append.

value + + +String + + + +

The value of the parameter to append.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

The modified URI.

+
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + + + + + + +

(static) assertRequiredParameterHasType(parameter, name, type) → {*}

+ + + + + +
+

Asserts that the given parameter is present and has the expected type.
+This method is intended to be called when you need to validate input parameters of functions. +Examples: + assertRequiredParameterHasType(5, 'name', 'number') => returns 5 + assertRequiredParameterHasType({}, 'name', CustomClass) => throws an Error

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
parameter + + +* + + + +

The parameter to validate.

name + + +String + + + +

The name of the parameter, as given to the calling function. + This is used to format the error message contained by the thrown Error.

type + + +String +| + +Type + + + +

The expected type of the parameter.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Throws:
+ + + +
+
+
+

If the parameter is not defined or is not an object.

+
+
+
+
+
+
+ Type +
+
+ +Error + + +
+
+
+
+
+ + + + + +
Returns:
+ + +
+

The validated parameter, as-is.

+
+ + + +
+
+ Type +
+
+ +* + + +
+
+ + + + + + + + + + +

(static) assertRequiredParameterIsArrayWithMinimumLength(parameter, name, lengthopt) → {*}

+ + + + + +
+

Asserts that the given parameter is an Array with a minimum length.
+This method is intended to be called when you need to validate input parameters of functions.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
parameter + + +* + + + + + + + + + + + +

The parameter to validate.

name + + +String + + + + + + + + + + + +

The name of the parameter, as given to the calling function. + This is used to format the error message contained by the thrown Error.

length + + +Number + + + + + + <optional>
+ + + + + +
+ + 0 + +

The minimum required length of the array.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Throws:
+ + + +
+
+
+

If the parameter is not an array of does not have the minimum length.

+
+
+
+
+
+
+ Type +
+
+ +Error + + +
+
+
+
+
+ + + + + +
Returns:
+ + +
+

The validated parameter, as-is.

+
+ + + +
+
+ Type +
+
+ +* + + +
+
+ + + + + + + + + + +

(static) assertRequiredParameterIsObject(parameter, name) → {*}

+ + + + + +
+

Asserts that the given parameter is present and is an object.
+This method is intended to be called when you need to validate input parameters of functions.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
parameter + + +* + + + +

The parameter to validate.

name + + +String + + + +

The name of the parameter, as given to the calling function. + This is used to format the error message contained by the thrown Error.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Throws:
+ + + +
+
+
+

If the parameter is not defined or is not an object.

+
+
+
+
+
+
+ Type +
+
+ +Error + + +
+
+
+
+
+ + + + + +
Returns:
+ + +
+

The validated parameter, as-is.

+
+ + + +
+
+ Type +
+
+ +* + + +
+
+ + + + + + + + + + +

(static) assertRequiredParameterIsPresent(parameter, name, message) → {*}

+ + + + + +
+

Asserts that the given parameter is present (read: truthy).
+This method is intended to be called when you need to validate input parameters of functions.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
parameter + + +* + + + +

The parameter to validate.

name + + +String + + + +

The name of the parameter, as given to the calling function. + This is used to format the error message contained by the thrown Error.

message + + +String + + + +

Optionnal alternative message to display when error

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Throws:
+ + + +
+
+
+

If the parameter is not defined.

+
+
+
+
+
+
+ Type +
+
+ +Error + + +
+
+
+
+
+ + + + + +
Returns:
+ + +
+

The validated parameter, as-is.

+
+ + + +
+
+ Type +
+
+ +* + + +
+
+ + + + + + + + + + +

(static) assertValidJMAPResponse(request, data) → {*}

+ + + + + +
+

Asserts that the given data is a valid JMAP response.
+This method is intended to be called by instances of Client, or by any other object making JMAP requests, +when validation of the response is required.
+
+The following checks are made by this method:

+
    +
  • data is defined and is an array
  • +
  • data has one or more elements, and all elements are arrays
  • +
  • data[0][0] is either
      +
    • the expected response string (computed with the help of the request parameter)
    • +
    • 'error'
    • +
    • an unknown response
    • +
    +
  • +
  • data[0][1] exists
  • +
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
request + + +String + + + +

The JMAP request to check the response for. This should be a valid JMAP request name.

data + + +* + + + +

The JMAP response to validate.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + +
Throws:
+ + + +
+
+
+

If the received data is not a valid JMAP response.

+
+
+
+
+
+
+ Type +
+
+ +Error + + +
+
+
+
+
+ + + + + +
Returns:
+ + +
+

The data, as-is, if it is detected as a valid JMAP response.

+
+ + + +
+
+ Type +
+
+ +* + + +
+
+ + + + + + + + + + +

(static) capitalize(str) → {String}

+ + + + + +
+

Capitalizes the given String, that is, returns the same string with the first character in uppercase.
+If undefined, null, the empty string or something else that a string is given, the argument is returned as-is.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
str + + +String + + + +

The String to capitalize.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

The capitalized String.

+
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + + + + + + +

(static) fillURITemplate(uri, parameters) → {String}

+ + + + + +
+

Fills a URI template by substituting variables by their corresponding values.
+This supports Level 1 URI templates only, as per this RFC.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
uri + + +String + + + +

The URI template to fill.

parameters + + +Object + + + +

A hash of name/value pairs used for variables substitution.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

The filled URI template.

+
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + + + + + + +

(static) isDefined(parameter) → {Boolean}

+ + + + + +
+

Check is the parameter is not undefined and not null.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
parameter + + +* + + + +

The parameter to check.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

True if parameter is not undefined and not null.

+
+ + + +
+
+ Type +
+
+ +Boolean + + +
+
+ + + + + + + + + + +

(static) nthElementOrDefault(array, index, defaultValue) → {*}

+ + + + + +
+

Returns the value at index in the given Array, or the default value if the array is undefined, null, +if index is negative or there is not enough elements in the array.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
array + +

The Array to get the value from.

index + +

The index of the desired value.

defaultValue + +

The default value to return if the element cannot be found in the array.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

The found value or the given default.

+
+ + + +
+
+ Type +
+
+ +* + + +
+
+ + + + + + + + + + +

(static) objectValues(object)

+ + + + + +
+

Can't make babel pollyfills to work with Karma. This is a hackity hack. +Object.values is part of ES7 standard.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
object + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/VacationResponse.html b/doc/api/VacationResponse.html new file mode 100644 index 0000000..988254b --- /dev/null +++ b/doc/api/VacationResponse.html @@ -0,0 +1,844 @@ + + + + + JSDoc: Class: VacationResponse + + + + + + + + + + +
+ +

Class: VacationResponse

+ + + + + + +
+ +
+ +

VacationResponse

+ + +
+ +
+
+ + + + + +

new VacationResponse(jmap, optsopt)

+ + + + + +
+

This class represents a JMAP VacationResponse.
+The VacationResponse object represents the state of vacation-response related settings for an account.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
jmap + + +Client + + + + + + + + + +

The Client instance that created this VacationResponse.

opts + + +Object + + + + + + <optional>
+ + + + + +

The optional properties of this VacationResponse.

+
Properties
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDefaultDescription
isEnabled + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

Is the vacation response enabled?

isActivated + + +Boolean + + + + + + <optional>
+ + + + + +
+ + false + +

Is the vacation response activated?

fromDate + + +Date + + + + + + <optional>
+ + + + + +
+ + null + +

The date/time after which messages that arrive should receive the user’s vacation response, in UTC.

toDate + + +Date + + + + + + <optional>
+ + + + + +
+ + null + +

The date/time after which messages that arrive should no longer receive the user’s vacation response, in UTC.

subject + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The subject that will be used by the mail sent in response to messages when the vacation response is enabled.

textBody + + +Number + + + + + + <optional>
+ + + + + +
+ + null + +

The plain text part of the message to send in response to messages when the vacation response is enabled.

htmlBody + + +String + + + + + + <optional>
+ + + + + +
+ + null + +

The HTML part of the message to send in response to messages when the vacation response is enabled.

+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +
+ + +

Extends

+ + + + + + + + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) fromJSONObject(jmap, object) → {VacationResponse}

+ + + + + +
+

Creates an VacationResponse from its JSON representation.

+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
jmap + + +Client + + + +

The Client instance that created this VacationResponse.

object + + +Object + + + +

The JSON representation of the VacationResponse, as a Javascript object.

+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +VacationResponse + + +
+
+ + + + + + + + + + +

toJSONObject()

+ + + + + +
+

Creates a JSON representation from this VacationResponse.

+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + +
Returns:
+ + +
+

JSON object with only owned properties and non-null default values.

+
+ + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/client_Client.js.html b/doc/api/client_Client.js.html new file mode 100644 index 0000000..16f2d07 --- /dev/null +++ b/doc/api/client_Client.js.html @@ -0,0 +1,831 @@ + + + + + JSDoc: Source: client/Client.js + + + + + + + + + + +
+ +

Source: client/Client.js

+ + + + + + +
+
+
'use strict';
+
+import ES6PromiseProvider from './../promises/ES6PromiseProvider.js';
+import Utils from './../utils/Utils.js';
+import Account from './../models/Account.js';
+import Mailbox from './../models/Mailbox.js';
+import MessageList from './../models/MessageList.js';
+import SetResponse from './../models/SetResponse.js';
+import Thread from './../models/Thread.js';
+import Message from './../models/Message.js';
+import OutboundMessage from './../models/OutboundMessage.js';
+import CreateMessageAck from './../models/CreateMessageAck.js';
+import MailboxRole from './../models/MailboxRole.js';
+import AuthContinuation from './../models/AuthContinuation.js';
+import AuthAccess from './../models/AuthAccess.js';
+import Constants from '../utils/Constants.js';
+import VacationResponse from './../models/VacationResponse';
+import JmapError from '../errors/JmapError';
+import FilterRule from '../models/FilterRule';
+
+export default class Client {
+  /**
+   * The {@link Client} class is the main entry point for sending JMAP requests to a remote server.<br />
+   * It uses a fluent API so that it's easy to chain calls. JMAP requests are sent using one of the _getXXX_ methods
+   * that map to their equivalent in the JMAP specification. For instance, if you want to do a _getAccounts_ request,
+   * you'll use the {@link Client#getAccounts} method.
+   *
+   * @param transport {Transport} The {@link Transport} instance used to send HTTP requests.
+   * @param [promiseProvider={@link ES6PromiseProvider}] {PromiseProvider} The {@link PromiseProvider} implementation to use.
+   */
+  constructor(transport, promiseProvider) {
+    Utils.assertRequiredParameterIsPresent(transport, 'transport');
+
+    this.promiseProvider = promiseProvider || new ES6PromiseProvider();
+    this.transport = transport;
+    this.transport.promiseProvider = this.promiseProvider;
+  }
+
+  /**
+   * Registers an authentication URL, that will be used as the endpoint to send authentication requests to the server.<br />
+   * <br />
+   * The URL will be exposed as the `authenticationUrl` property afterwards.
+   *
+   * @param url {String} The authentication url to use in JMAP requests.
+   *
+   * @return {Client} This Client instance.
+   */
+  withAuthenticationUrl(url) {
+    this.authenticationUrl = url;
+
+    return this;
+  }
+
+  /**
+   * Registers an authentication token, obtained by an external mechanism from the target JMAP server.<br />
+   * This token will then be used as the `Authorization` header, as per {@link http://jmap.io/spec.html#authenticating-http-requests}.<br />
+   * <br />
+   * The token will be exposed as the `authToken` property afterwards.
+   *
+   * @param token {String} The authentication token to use in JMAP requests.
+   * @param [scheme] {String} The authentication scheme according to RFC 7235
+   *
+   * @return {Client} This Client instance.
+   */
+  withAuthenticationToken(token, scheme) {
+    this.authToken = token;
+    this.authScheme = scheme;
+
+    return this;
+  }
+
+  /**
+   * Sets the API URL of the target JMAP server. All JMAP requests will be sent to this URL.<br />
+   * <br />
+   * The URL will be exposed as the `apiUrl` property afterwards.
+   *
+   * @param url {String} The API URL of the JMAP server.
+   *
+   * @return {Client} This Client instance.
+   */
+  withAPIUrl(url) {
+    this.apiUrl = url;
+
+    return this;
+  }
+
+  /**
+   * Sets the download URL, i.e.: the URL used to download attachments to {@link Message}s.<br />
+   * <br />
+   * The URL will be exposed as the `downloadUrl` property afterwards.
+   *
+   * @param url {String} The download URL of the JMAP server.
+   *
+   * @return {Client} This Client instance.
+   */
+  withDownloadUrl(url) {
+    this.downloadUrl = url;
+
+    return this;
+  }
+
+  /**
+   * Initializes the client with an {@link AuthAccess} model from an authentication response.<br />
+   * <br />
+   * The individual properties of the AuthAccess object will be copied into client properties.
+   *
+   * @param access {AuthAccess|Object} The response object from an authenticate process.
+   *
+   * @return {Client} This Client instance.
+   */
+  withAuthAccess(access) {
+    Utils.assertRequiredParameterIsObject(access, 'access');
+
+    // create an instance of AuthAccess if plain object is given
+    if (!(access instanceof AuthAccess)) {
+      access = new AuthAccess(this, access);
+    }
+
+    this.authAccess = access;
+    this.authScheme = 'X-JMAP';
+    this.authToken = access.accessToken;
+    ['username', 'signingId', 'signingKey', 'apiUrl', 'eventSourceUrl', 'uploadUrl', 'downloadUrl', 'serverCapabilities', 'mailCapabilities'].forEach((property) => {
+      this[property] = access[property];
+    });
+
+    return this;
+  }
+
+  /**
+   * Implement the 2-step JMAP authentication protocol.<br />
+   * This method abstract the two authentication steps:
+   *
+   * 1. query the JMAP server to get a continuation token
+   * 2. query the JMAP server with the continuation token (and password), to get the final accessToken.
+   *
+   * @param username {String} The username to authenticate with
+   * @param deviceName {String} A unique device name
+   * @param continuationCallback {Function} A function that takes an {@link AuthContinuation}
+   *   object as argument, and should return a promise, that will eventually resolve with an
+   *   object denoting the chosen authentication method and the optional password (if method == password).
+   *
+   * @return {Promise} A {@link Promise} that will eventually be resovled with a {@link AuthAccess} object
+   */
+  authenticate(username, deviceName, continuationCallback) {
+    return this.transport
+      .post(this.authenticationUrl, this._defaultNonAuthenticatedHeaders(), {
+        username: username,
+        deviceName: deviceName,
+        clientName: Constants.CLIENT_NAME,
+        clientVersion: Constants.VERSION
+      })
+      .then(data => this._authenticateResponse(data, continuationCallback));
+  }
+
+  /**
+   * Sub-routine handling JMAP server responses on authentication requests
+   *
+   * Depending on the server's response, this either (recursively) executes the second
+   * authentication step by calling the provided continuationCallback or resolves on
+   * successfully completed authentication.
+   *
+   * @param data {Object} The JMAP response data
+   * @param continuationCallback {Function} The callback function initially passed to the authenticate() method
+   *
+   * @return {Promise} A {@link Promise} that will eventually be resovled with a {@link AuthAccess} object
+   */
+  _authenticateResponse(data, continuationCallback) {
+    if (data.loginId && data.accessToken === undefined) {
+      // got an AuthContinuation response
+      var authContinuation = new AuthContinuation(data);
+
+      return continuationCallback(authContinuation)
+        .then(continueData => {
+          if (!authContinuation.supports(continueData.type)) {
+            throw new Error('The "' + continueData.type + '" authentication type is not supported by the server.');
+          }
+          let param = {
+            loginId: authContinuation.loginId,
+            type: continueData.type
+          };
+
+          if (continueData.value) {
+            param.value = continueData.value;
+          }
+
+          return this.transport
+            .post(this.authenticationUrl, this._defaultNonAuthenticatedHeaders(), param);
+        })
+        .then(resp => this._authenticateResponse(resp, continuationCallback));
+    } else if (data.accessToken && data.loginId === undefined) {
+      // got auth access response
+      return new AuthAccess(this, data);
+    } else {
+      // got unknown response data
+      throw new Error('Unexpected response on authorization request');
+    }
+  }
+
+  /**
+   * Implement the JMAP external authentication protocol.<br />
+   * This method abstract the two authentication steps:
+   *
+   * 1. query the JMAP server to get a continuation token
+   * 2. query the JMAP server with the continuation token, to get the final accessToken.
+   *
+   * <br />
+   * Between those two steps, a user provided function wil be called to handle the external
+   * authentication part.
+   * <br />
+   * This method returns a promise that will eventually be resovled with a {@link AuthAccess} object.
+   * It's the responsability of the caller to then set the AuthToken using for example:
+   * <br />
+   *
+   *     client.withAuthenticationToken(authAccess.accessToken);
+   *
+   * @param username {String} The username of the user to authenticate.
+   * @param deviceName {String} A unique device name
+   * @param continuationCallback {Function} A function that takes an {@link AuthContinuation} object as argument, and should return a promise, that will resolve once the external authentication is complete.
+   *
+   * @return {Promise} A {@link Promise} that will eventually be resovled with a {@link AuthAccess} object
+   */
+  authExternal(username, deviceName, continuationCallback) {
+    return this.authenticate(username, deviceName, function(authContinuation) {
+      // wrap the continuationCallback to resolve with method:'external'
+      return continuationCallback(authContinuation).then(() => ({ type: 'external' }));
+    });
+  }
+
+  /**
+   * Implement the JMAP password authentication protocol.<br />
+   * This method abstract the two authentication steps:
+   *
+   * 1. query the JMAP server to get a continuation token
+   * 2. query the JMAP server with the continuation token and the password, to get the final accessToken.
+   *
+   * @param username {String} The username of the user to authenticate
+   * @param password {String} The password of the user to authenticate
+   * @param deviceName {String} A unique device name
+   *
+   * @return {Promise} A {@link Promise} that will eventually be resovled with a {@link AuthAccess} object
+   */
+  authPassword(username, password, deviceName) {
+    return this.authenticate(username, deviceName, function() {
+      return this.promiseProvider.newPromise(function(resolve, reject) {
+        resolve({ type: 'password', value: password });
+      });
+    }.bind(this));
+  }
+
+  /**
+   * Sends a _getAccounts_ JMAP request.
+   *
+   * @param [options=null] {Object} The options to the _getAccounts_ JMAP request.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to an array of {@link Account} objects.
+   *
+   * @see http://jmap.io/spec.html#getaccounts
+   */
+  getAccounts(options) {
+    // resolve with accounts list from AuthAccess
+    if (this.authAccess instanceof AuthAccess) {
+      return this.promiseProvider.newPromise(function(resolve, reject) {
+        let accounts = [];
+
+        // equivalent to Object.values()
+        for (let id in this.authAccess.accounts) {
+          if (this.authAccess.accounts.hasOwnProperty(id)) {
+            accounts.push(this.authAccess.accounts[id]);
+          }
+        }
+
+        resolve(accounts);
+      }.bind(this));
+    }
+
+    // fallback to deprecated getAccounts request
+    return this._jmapRequest('getAccounts', options);
+  }
+
+  /**
+   * Sends a _getMailboxes_ JMAP request.
+   *
+   * @param [options=null] {Object} The options to the _getMailboxes_ JMAP request.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to an array of {@link Mailbox} objects.
+   *
+   * @see http://jmap.io/spec.html#getmailboxes
+   */
+  getMailboxes(options) {
+    return this._jmapRequest('getMailboxes', options);
+  }
+
+  /**
+   * Sends a _setMailboxes_ JMAP request.
+   *
+   * @param [options=null] {Object} The options to the _setMailboxes_ JMAP request.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to a {@link Mailbox} object.
+   *
+   * @see http://jmap.io/spec.html#setmailboxes
+   */
+  setMailboxes(options) {
+    return this._jmapRequest('setMailboxes', options);
+  }
+
+  /**
+   * Creates a mailbox  by sending a _setMailboxes_ JMAP request.<br />
+   *
+   * @param name {String} The name of the mailbox to create.
+   * @param [parentId=null] {String} The id of the parent of the mailbox to create.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to a {@link Mailbox}.
+   *
+   * @see http://jmap.io/spec.html#creating-mailboxes
+   */
+  createMailbox(name, parentId) {
+    Utils.assertRequiredParameterIsPresent(name, 'name');
+
+    var clientId = this._generateClientId();
+
+    return this.setMailboxes({
+      create: {
+        [clientId]: {
+          name: name,
+          parentId: parentId
+        }
+      }
+    }).then(response => {
+      var created = response.created[clientId];
+
+      if (!created) {
+        throw new Error('Failed to create mailbox, clientId: ' + clientId + ', message: ' + (response.notCreated[clientId] || 'none'));
+      }
+
+      return new Mailbox(this, created.id, created.name || name, created);
+    });
+  }
+
+  /**
+   * Updates properties of a {@link Mailbox}.<br />
+   * This will issue a {@link Client#setMailboxes} JMAP request under the hoods, passing the correct options.
+   *
+   * @param id {String} The id of the {@link Mailbox} to update.
+   * @param options {Object} The options of the target mailbox to be updated.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to nothing if the mailbox was updated successfully.
+   *
+   * @see http://jmap.io/spec.html#updating-mailboxes
+   */
+  updateMailbox(id, options) {
+    Utils.assertRequiredParameterIsPresent(id, 'id');
+
+    return this.setMailboxes({
+      update: {
+        [id]: options
+      }
+    }).then(response => {
+      if (response.updated.indexOf(id) < 0) {
+        throw new Error('Failed to update mailbox ' + id + ', the reason is: ' + response.notUpdated[id]);
+      }
+    });
+  }
+
+  /**
+   * Destroy the {@link Mailbox} related to the given _id_ on the server.<br />
+   * This will issue a {@link Client#destroyMailboxes} request under the hoods, passing _[id]_ option.
+   *
+   * @param id {String} The id of the mailbox to destroy.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to nothing if the {@link Mailbox} was destroyed successfully.
+   *
+   */
+  destroyMailbox(id) {
+    Utils.assertRequiredParameterIsPresent(id, 'id');
+
+    return this.destroyMailboxes([id]);
+  }
+
+  /**
+   * Destroy multiple {@link Mailbox}es specified to the given _ids_ on the server.<br />
+   * This will issue a {@link Client#setMailboxes} JMAP request under the hoods, passing the correct options.
+   *
+   * @param ids {String[]} An array IDs of the mailboxes to destroy. These IDs must be in the right order: Destroy X comes before destroy Y if X is a descendent of Y.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to nothing if all {@link Mailbox}es were destroyed successfully. Otherwise, it rejects error message of the first `notDestroyed` mailbox.
+   *
+   * @see http://jmap.io/spec.html#destroying-mailboxes
+   */
+  destroyMailboxes(ids) {
+    Utils.assertRequiredParameterIsArrayWithMinimumLength(ids, 'ids', 1);
+
+    return this.setMailboxes({
+      destroy: ids
+    }).then(response => {
+      let notDestroyedIds = Object.keys(response.notDestroyed);
+
+      if (notDestroyedIds.length > 0) {
+        // take the first one for incrementally debugging
+        let setError = response.notDestroyed[notDestroyedIds[0]];
+        let reason = setError.type + ' (' + setError.description + ')';
+
+        throw new Error('Failed to destroy ' + notDestroyedIds[0] + ', the reason is: ' + reason);
+      }
+    });
+  }
+
+  /**
+   * Finds a {@link Mailbox} with the given role.<br />
+   * This will issue a _getMailboxes_ JMAP request and search for the mailbox in the returned list.
+   *
+   * @param role {MailboxRole|String} The desired mailbox role.
+   * @param [options=null] {Object} The options to the implicit _getMailboxes_ JMAP request.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to the {@link Mailbox} if found.
+   *
+   * @see MailboxRole
+   */
+  getMailboxWithRole(role, options) {
+    if (!(role instanceof MailboxRole)) {
+      role = MailboxRole.fromRole(role);
+    }
+
+    if (role === MailboxRole.UNKNOWN) {
+      throw new Error('A valid role is required to find a mailbox by role');
+    }
+
+    return this._jmapRequest('getMailboxes', options)
+      .then((mailboxes) => {
+        for (let i = 0; i < mailboxes.length; i++) {
+          if (mailboxes[i].role === role) {
+            return mailboxes[i];
+          }
+        }
+
+        throw new Error('Cannot find a mailbox with role ' + role.value);
+      });
+  }
+
+  /**
+   * Sends a _getMessageList_ JMAP request.
+   *
+   * @param [options=null] {Object} The options to the _getMessageList_ JMAP request.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to a {@link MessageList} object.
+   *
+   * @see http://jmap.io/spec.html#getmessagelist
+   */
+  getMessageList(options) {
+    return this._jmapRequest('getMessageList', options);
+  }
+
+  /**
+   * Sends a _getThreads_ JMAP request.
+   *
+   * @param [options=null] {Object} The options to the _getThreads_ JMAP request.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to an array of {@link Thread} objects.
+   *
+   * @see http://jmap.io/spec.html#getthreads
+   */
+  getThreads(options) {
+    return this._jmapRequest('getThreads', options);
+  }
+
+  /**
+   * Sends a _getMessages_ JMAP request.
+   *
+   * @param [options=null] {Object} The options to the _getMessages_ JMAP request.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to an array of {@link Message} objects.
+   *
+   * @see http://jmap.io/spec.html#getmessages
+   */
+  getMessages(options) {
+    return this._jmapRequest('getMessages', options);
+  }
+
+  /**
+   * Sends a _setMessages_ JMAP request.
+   *
+   * @param [options=null] {Object} The options to the _setMessages_ JMAP request.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to a {@link SetResponse} object.
+   *
+   * @see http://jmap.io/spec.html#setmessages
+   */
+  setMessages(options) {
+    return this._jmapRequest('setMessages', options);
+  }
+
+  /**
+   * Updates properties of a {@link Message}.<br />
+   * This will issue a {@link Client#setMessages} JMAP request under the hoods, passing the correct options.
+   *
+   * @param id {String} The id of the {@link Message} to update.
+   * @param options {Object} The options of the target message to be updated.
+   * @param options.mailboxIds {String[]} The identifiers of the new mailboxes for the message.
+   * @param options.isFlagged {Boolean} This corresponds whether the message is flagged or not
+   * @param options.isUnread {Boolean} This corresponds whether the message has been yet read or not
+   * @param options.isAnswered {Boolean} This corresponds whether the message has been yet replied or not
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to nothing if the message was updated successfully.
+   *
+   * @see http://jmap.io/spec.html#updating-messages
+   */
+  updateMessage(id, options) {
+    Utils.assertRequiredParameterIsPresent(id, 'id');
+    Utils.assertRequiredParameterIsObject(options, 'options');
+
+    return this.setMessages({
+      update: {
+        [id]: options
+      }
+    }).then(response => {
+      if (response.updated.indexOf(id) < 0) {
+        throw new Error('Failed to update message ' + id + ', the reason is: ' + (response.notUpdated[id] || 'missing'));
+      }
+    });
+  }
+
+  /**
+   * Destroy the {@link Message} related to the given _id_ on the server.<br />
+   * This will issue a {@link Client#setMessages} JMAP request under the hoods, passing the correct options.
+   *
+   * @param id {String} The id of the object to destroy.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to nothing if the {@link Message} was destroyed successfully.
+   *
+   * @see Client#setMessages
+   */
+  destroyMessage(id) {
+    return this.destroyMessages(id && [id]).then(response => {
+      if (response.destroyed.indexOf(id) < 0) {
+        throw new Error('Failed to destroy ' + id + ', the reason is: ' + (response.notDestroyed[id] || 'missing'));
+      }
+    });
+  }
+
+  /**
+   * Destroy several {@link Message}s at once.<br />
+   * This will issue a {@link Client#setMessages} JMAP request under the hoods, passing the correct options.
+   *
+   * @param ids {String[]} The list of ids of the messages to destroy.
+   *
+   * @return {Promise} A {@link Promise} that resolves to a {@link SetResponse}, containing the result of the operation.
+   *
+   * @see Client#setMessages
+   */
+  destroyMessages(ids) {
+    Utils.assertRequiredParameterIsArrayWithMinimumLength(ids, 'ids', 1);
+
+    return this.setMessages({ destroy: ids });
+  }
+
+  /**
+   * Save a message as draft by sending a _setMessages_ JMAP request.<br />
+   * The _mailboxIds_ and _isDraft_ properties of the given _message_ will be overridden by this method.
+   *
+   * @param message {OutboundMessage} The message to save.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to a {@link CreateMessageAck}.
+   *
+   * @see http://jmap.io/spec.html#saving-a-draft
+   */
+  saveAsDraft(message) {
+    return this._createMessage(message, MailboxRole.DRAFTS);
+  }
+
+  /**
+   * Sends a message by issuing a _setMessages_ JMAP request.<br />
+   * The _mailboxIds_ and _isDraft_ properties of the given _message_ will be overridden by this method.
+   *
+   * @param message {OutboundMessage} The message to send.
+   * @param outbox {Mailbox} The {@link Mailbox} with role='outbox', if already available
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to a {@link CreateMessageAck}.
+   *
+   * @see http://jmap.io/spec.html#sending-messages
+   */
+  send(message, outbox) {
+    return this._createMessage(message, MailboxRole.OUTBOX, outbox);
+  }
+
+  /**
+   * Moves a {@link Message} to a different set of mailboxes.<br />
+   * This will issue a {@link Client#setMessages} JMAP request under the hoods, passing the correct options.
+   *
+   * @param id {String} The id of the {@link Message} to move.
+   * @param mailboxIds {String[]} The identifiers of the target mailboxes for the message.
+   *
+   * @return {Promise} A {@link Promise} that eventually resolves to nothing if the message was moved successfully.
+   *
+   * @see Client#setMessages
+   */
+  moveMessage(id, mailboxIds) {
+    Utils.assertRequiredParameterIsPresent(id, 'id');
+    Utils.assertRequiredParameterIsArrayWithMinimumLength(mailboxIds, 'mailboxIds', 1);
+
+    return this.updateMessage(id, { mailboxIds: mailboxIds });
+  }
+
+  /**
+   * Gets the singleton {@link VacationResponse} instance for a given account.<br />
+   * This will send a `getVacationResponse` request to the JMAP backend.
+   *
+   * @param [options] {Object} The options to the underlying `getVacationResponse` JMAP request.
+   * @param [options.accountId=null] {String} The account ID to get the vacation response for. If `null`, the primary account is used.
+   *
+   * @returns {Promise} A {@link Promise} that eventually resolves to the {@link VacationResponse} instance.
+   */
+  getVacationResponse(options) {
+    return this._jmapRequest('getVacationResponse', options).then(list => list[0]);
+  }
+
+  /**
+   * Sets the singleton {@link VacationResponse} instance for a given account.<br />
+   * This will send a `setVacationResponse` request to the JMAP backend.
+   *
+   * @param vacationResponse {VacationResponse} The {@link VacationResponse} instance to set
+   * @param [options] {Object} The options to the underlying `setVacationResponse` JMAP request.
+   * @param [options.accountId=null] {String} The account ID to set the vacation response for. If `null`, the primary account is used.
+   *
+   * @returns {Promise} A {@link Promise} that eventually resolves to nothing upon success.
+   */
+  setVacationResponse(vacationResponse, options) {
+    Utils.assertRequiredParameterHasType(vacationResponse, 'vacationResponse', VacationResponse);
+
+    return this._jmapRequest('setVacationResponse', {
+      accountId: options && options.accountId,
+      update: {
+        [VacationResponse.ID]: vacationResponse.toJSONObject()
+      }
+    }).then(response => {
+      if (response.updated.indexOf(VacationResponse.ID) < 0) {
+        throw new Error('Failed to set vacation response. Error: ' + (response.notUpdated[VacationResponse.ID] || 'none'));
+      }
+    });
+  }
+
+  _createMessage(message, role, mailbox) {
+    Utils.assertRequiredParameterHasType(message, 'message', OutboundMessage);
+
+    let clientId = this._generateClientId(),
+        doSetMessages = mailbox => {
+          message.mailboxIds = [mailbox.id];
+          message.isDraft = MailboxRole.DRAFTS.value === role.value ? true : null;
+
+          return this.setMessages({
+            create: {
+              [clientId]: message.toJSONObject()
+            }
+          }).then(response => {
+            if (!response.created[clientId]) {
+              throw new Error('Failed to store message with clientId ' + clientId + '. Error: ' + (response.notCreated[clientId] || 'none'));
+            }
+
+            return new CreateMessageAck(this, response.created[clientId]);
+          });
+        };
+
+    return mailbox ? doSetMessages(mailbox) : this.getMailboxWithRole(role).then(doSetMessages);
+  }
+
+  _generateClientId() {
+    return Date.now();
+  }
+
+  /**
+   * Sets the singleton {@link FilterRule} instance for a given account.<br />
+   * This will send a `setFilter` request to the JMAP backend.
+   *
+   * @param filterRules {FilterRule[]|Object[]} The list of filter rules to set
+   * @param [options] {Object} The options to the underlying `setFilter` JMAP request.
+   * @param [options.accountId=null] {String} The account ID to set the filtering rules for. If `null`, the primary account is used.
+   *
+   * @returns {Promise} A {@link Promise} that eventually resolves to nothing upon success.
+   */
+  setFilter(filterRules, options) {
+    const filterRulesAsJson = filterRules.map(rule => rule instanceof FilterRule ? rule.toJSONObject() : rule);
+
+    return this._jmapRequest('setFilter', {
+      accountId: options && options.accountId,
+      ifInState: options && options.ifInState || null,
+      [FilterRule.ID]: filterRulesAsJson
+    }).then(response => {
+      if (response.updated.indexOf(FilterRule.ID) < 0) {
+        throw new Error('Failed to set filter. Error: ' + (response.notUpdated[FilterRule.ID] || 'none'));
+      }
+    });
+  }
+
+  getFilter(options) {
+    return this._jmapRequest('getFilter', options).then(response => response.singleton);
+  }
+
+  _defaultNonAuthenticatedHeaders() {
+    return {
+      Accept: 'application/json; charset=UTF-8',
+      'Content-Type': 'application/json; charset=UTF-8'
+    };
+  }
+
+  _defaultHeaders() {
+    return {
+      Accept: 'application/json; charset=UTF-8',
+      'Content-Type': 'application/json; charset=UTF-8',
+      Authorization: (this.authScheme ? this.authScheme + ' ' : '') + this.authToken
+    };
+  }
+
+  _jmapRequest(method, options) {
+    return this.transport
+      .post(this.apiUrl, this._defaultHeaders(), [[method, options || {}, '#0']])
+      .then(data => Utils.assertValidJMAPResponse(method, data))
+      .then(data => data.map(response => this._handleResponse(response, method)))
+      .then(responses => responses.length > 1 ? responses : responses[0]);
+  }
+
+  _handleResponse(response, method) {
+    let name = response[0],
+        fn = this[`_handle${Utils.capitalize(name)}Response`];
+
+    // This will return the "raw" data if the command is unknown to the client
+    return fn ? fn.bind(this)(response, method) : response[1];
+  }
+
+  _handleErrorResponse(response, method) {
+    throw new JmapError(response[1], method);
+  }
+
+  _handleListResponse(response, Model, filter) {
+    return Utils._jsonArrayToModelList(this, Model, response[1].list, filter);
+  }
+
+  _handleSetResponse(response) {
+    return SetResponse.fromJSONObject(this, response[1]);
+  }
+
+  _handleAccountsResponse(response) {
+    return this._handleListResponse(response, Account);
+  }
+
+  _handleThreadsResponse(response) {
+    return this._handleListResponse(response, Thread);
+  }
+
+  _handleMessagesResponse(response) {
+    return this._handleListResponse(response, Message, function(message) {
+      try {
+        return Utils.assertRequiredParameterIsArrayWithMinimumLength(message.mailboxIds, 'mailboxIds', 1);
+      } catch (err) {
+        return false;
+      }
+    });
+  }
+
+  _handleMailboxesResponse(response) {
+    return this._handleListResponse(response, Mailbox);
+  }
+
+  _handleMailboxesSetResponse(response) {
+    return this._handleSetResponse(response);
+  }
+
+  _handleMessageListResponse(response) {
+    return MessageList.fromJSONObject(this, response[1]);
+  }
+
+  _handleMessagesSetResponse(response) {
+    return this._handleSetResponse(response);
+  }
+
+  _handleVacationResponseResponse(response) {
+    return this._handleListResponse(response, VacationResponse);
+  }
+
+  _handleVacationResponseSetResponse(response) {
+    return this._handleSetResponse(response);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/errors_JmapError.js.html b/doc/api/errors_JmapError.js.html new file mode 100644 index 0000000..6125a9d --- /dev/null +++ b/doc/api/errors_JmapError.js.html @@ -0,0 +1,93 @@ + + + + + JSDoc: Source: errors/JmapError.js + + + + + + + + + + +
+ +

Source: errors/JmapError.js

+ + + + + + +
+
+
'use strict';
+
+import Utils from '../utils/Utils';
+
+export default class JmapError extends Error {
+  /**
+   * A `JmapError` is a custom `Error` thrown when a request is rejected by the JMAP backend. <br />
+   * The _type_ property holds the type of error that happened. Refer to the JMAP [spec](http://jmap.io/spec-core.html#errors)
+   * for details on the available errors. <br />
+   * Other properties may be present with further information; these are detailed in the method descriptions where appropriate.
+   *
+   * @constructor
+   *
+   * @param payload {Object} The error payload, from which detailed information about the error can be retrieved.
+   * @param [payload.type] {String} The type of this `JmapError`.
+   * @param [payload.description=null] {String} The description, if any, of this `JmapError`.
+   * @param [method=null] {String} The JMAP method that triggered this `JmapError`.
+   *
+   * @see Error
+   */
+  constructor(payload, method) {
+    super();
+
+    Utils.assertRequiredParameterIsPresent(payload, 'payload');
+    Utils.assertRequiredParameterIsPresent(payload.type, 'payload.type');
+
+    this.payload = payload;
+    this.type = payload.type;
+    this.description = payload.description || null;
+
+    this.method = method || null;
+  }
+
+  /**
+   * Returns a {@link String} representation of this `JmapError`.
+   *
+   * @returns {String} The human-readable representation of this `JmapError`.
+   */
+  toString() {
+    return `JmapError{type=${this.type},description=${this.description},method=${this.method}}`;
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/errors_TransportError.js.html b/doc/api/errors_TransportError.js.html new file mode 100644 index 0000000..91b577a --- /dev/null +++ b/doc/api/errors_TransportError.js.html @@ -0,0 +1,75 @@ + + + + + JSDoc: Source: errors/TransportError.js + + + + + + + + + + +
+ +

Source: errors/TransportError.js

+ + + + + + +
+
+
'use strict';
+
+export default class TransportError extends Error {
+  /**
+   * A `TransportError` is a custom `Error` thrown when a request to a remote server fails.
+   *
+   * @constructor
+   *
+   * @param [cause=null] {*} The underlying cause of this `TransportError`. Though this is usually an {@link Error}, this
+   *   might actually be anything and depends on the chosen {@link Transport} implementation.
+   * @param [statusCode=0] {Number} The HTTP status code sent by the server, if the request reached the server.
+   * @param [responseText=null] {String} The HTTP response sent by the server, if any.
+   *
+   * @see Transport
+   * @see Error
+   */
+  constructor(cause, statusCode, responseText) {
+    super();
+
+    this.cause = cause || null;
+    this.statusCode = statusCode || 0;
+    this.responseText = responseText || null;
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/fonts/OpenSans-Bold-webfont.eot b/doc/api/fonts/OpenSans-Bold-webfont.eot new file mode 100644 index 0000000..5d20d91 Binary files /dev/null and b/doc/api/fonts/OpenSans-Bold-webfont.eot differ diff --git a/doc/api/fonts/OpenSans-Bold-webfont.svg b/doc/api/fonts/OpenSans-Bold-webfont.svg new file mode 100644 index 0000000..3ed7be4 --- /dev/null +++ b/doc/api/fonts/OpenSans-Bold-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/api/fonts/OpenSans-Bold-webfont.woff b/doc/api/fonts/OpenSans-Bold-webfont.woff new file mode 100644 index 0000000..1205787 Binary files /dev/null and b/doc/api/fonts/OpenSans-Bold-webfont.woff differ diff --git a/doc/api/fonts/OpenSans-BoldItalic-webfont.eot b/doc/api/fonts/OpenSans-BoldItalic-webfont.eot new file mode 100644 index 0000000..1f639a1 Binary files /dev/null and b/doc/api/fonts/OpenSans-BoldItalic-webfont.eot differ diff --git a/doc/api/fonts/OpenSans-BoldItalic-webfont.svg b/doc/api/fonts/OpenSans-BoldItalic-webfont.svg new file mode 100644 index 0000000..6a2607b --- /dev/null +++ b/doc/api/fonts/OpenSans-BoldItalic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/api/fonts/OpenSans-BoldItalic-webfont.woff b/doc/api/fonts/OpenSans-BoldItalic-webfont.woff new file mode 100644 index 0000000..ed760c0 Binary files /dev/null and b/doc/api/fonts/OpenSans-BoldItalic-webfont.woff differ diff --git a/doc/api/fonts/OpenSans-Italic-webfont.eot b/doc/api/fonts/OpenSans-Italic-webfont.eot new file mode 100644 index 0000000..0c8a0ae Binary files /dev/null and b/doc/api/fonts/OpenSans-Italic-webfont.eot differ diff --git a/doc/api/fonts/OpenSans-Italic-webfont.svg b/doc/api/fonts/OpenSans-Italic-webfont.svg new file mode 100644 index 0000000..e1075dc --- /dev/null +++ b/doc/api/fonts/OpenSans-Italic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/api/fonts/OpenSans-Italic-webfont.woff b/doc/api/fonts/OpenSans-Italic-webfont.woff new file mode 100644 index 0000000..ff652e6 Binary files /dev/null and b/doc/api/fonts/OpenSans-Italic-webfont.woff differ diff --git a/doc/api/fonts/OpenSans-Light-webfont.eot b/doc/api/fonts/OpenSans-Light-webfont.eot new file mode 100644 index 0000000..1486840 Binary files /dev/null and b/doc/api/fonts/OpenSans-Light-webfont.eot differ diff --git a/doc/api/fonts/OpenSans-Light-webfont.svg b/doc/api/fonts/OpenSans-Light-webfont.svg new file mode 100644 index 0000000..11a472c --- /dev/null +++ b/doc/api/fonts/OpenSans-Light-webfont.svg @@ -0,0 +1,1831 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/api/fonts/OpenSans-Light-webfont.woff b/doc/api/fonts/OpenSans-Light-webfont.woff new file mode 100644 index 0000000..e786074 Binary files /dev/null and b/doc/api/fonts/OpenSans-Light-webfont.woff differ diff --git a/doc/api/fonts/OpenSans-LightItalic-webfont.eot b/doc/api/fonts/OpenSans-LightItalic-webfont.eot new file mode 100644 index 0000000..8f44592 Binary files /dev/null and b/doc/api/fonts/OpenSans-LightItalic-webfont.eot differ diff --git a/doc/api/fonts/OpenSans-LightItalic-webfont.svg b/doc/api/fonts/OpenSans-LightItalic-webfont.svg new file mode 100644 index 0000000..431d7e3 --- /dev/null +++ b/doc/api/fonts/OpenSans-LightItalic-webfont.svg @@ -0,0 +1,1835 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/api/fonts/OpenSans-LightItalic-webfont.woff b/doc/api/fonts/OpenSans-LightItalic-webfont.woff new file mode 100644 index 0000000..43e8b9e Binary files /dev/null and b/doc/api/fonts/OpenSans-LightItalic-webfont.woff differ diff --git a/doc/api/fonts/OpenSans-Regular-webfont.eot b/doc/api/fonts/OpenSans-Regular-webfont.eot new file mode 100644 index 0000000..6bbc3cf Binary files /dev/null and b/doc/api/fonts/OpenSans-Regular-webfont.eot differ diff --git a/doc/api/fonts/OpenSans-Regular-webfont.svg b/doc/api/fonts/OpenSans-Regular-webfont.svg new file mode 100644 index 0000000..25a3952 --- /dev/null +++ b/doc/api/fonts/OpenSans-Regular-webfont.svg @@ -0,0 +1,1831 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doc/api/fonts/OpenSans-Regular-webfont.woff b/doc/api/fonts/OpenSans-Regular-webfont.woff new file mode 100644 index 0000000..e231183 Binary files /dev/null and b/doc/api/fonts/OpenSans-Regular-webfont.woff differ diff --git a/doc/api/index.html b/doc/api/index.html new file mode 100644 index 0000000..0ae358a --- /dev/null +++ b/doc/api/index.html @@ -0,0 +1,65 @@ + + + + + JSDoc: Home + + + + + + + + + + +
+ +

Home

+ + + + + + + + +

+ + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/models_Account.js.html b/doc/api/models_Account.js.html new file mode 100644 index 0000000..ddaf89f --- /dev/null +++ b/doc/api/models_Account.js.html @@ -0,0 +1,163 @@ + + + + + JSDoc: Source: models/Account.js + + + + + + + + + + +
+ +

Source: models/Account.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import Utils from '../utils/Utils.js';
+import JSONBuilder from '../utils/JSONBuilder.js';
+
+export default class Account extends Model {
+  /**
+   * This class represents a JMAP [Account]{@link http://jmap.io/spec.html#accounts}.
+   *
+   * @constructor
+   * @extends Model
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _Account_.
+   * @param id {String} The unique identifier of this _Account_.
+   * @param [opts] {Object} The optional properties of this _Account_.
+   * @param [opts.name=''] {String} The name of this _Account_.
+   * @param [opts.isPrimary=false] {Boolean} Whether this _Account_ is the primary email account.
+   * @param [opts.isReadOnly=false] {Boolean} Whether the entire _Account_ is read-only
+   * @param [opts.hasDataFor=[]] {String[]} A list of the data profiles available in this account
+server.
+   *
+   * @see Model
+   */
+  constructor(jmap, id, opts) {
+    super(jmap);
+
+    Utils.assertRequiredParameterIsPresent(id, 'id');
+
+    opts = opts || {};
+
+    this.id = id;
+    this.name = opts.name || '';
+    this.isPrimary = opts.isPrimary || false;
+    this.isReadOnly = opts.isReadOnly || false;
+    this.hasDataFor = opts.hasDataFor || [];
+  }
+
+  /**
+   * Returns whether this `Account` supports mail or not.
+   *
+   * @returns {Boolean} _true_ if and only if this `Account` has mail enabled, _false_ otherwise.
+   */
+  hasMail() {
+    return this.hasDataFor.indexOf('mail') >= 0;
+  }
+
+  /**
+   * Returns whether this `Account` supports calendars or not.
+   *
+   * @returns {Boolean} _true_ if and only if this `Account` has calendars enabled, _false_ otherwise.
+   */
+  hasCalendars() {
+    return this.hasDataFor.indexOf('calendars') >= 0;
+  }
+
+  /**
+   * Returns whether this `Account` supports contacts or not.
+   *
+   * @returns {Boolean} _true_ if and only if this `Account` has contacts enabled, _false_ otherwise.
+   */
+  hasContacts() {
+    return this.hasDataFor.indexOf('contacts') >= 0;
+  }
+
+  /**
+   * Fetches all mailboxes of this _Account_.<br />
+   * This will delegate to {@link Client#getMailboxes}, passing this Account's _id_ as the _accountId_ option.
+   *
+   * @param [options] {Object} The options object passed to {@link Client#getMailboxes}.
+   *   Please note that the _accountId_ option will be overriden if defined.
+   * @returns {Promise} A promise that eventually resolves with an array of {@link Mailbox} instances.
+   *
+   * @see Client#getMailboxes
+   * @see PromiseProvider
+   */
+  getMailboxes(options) {
+    options = options || {};
+    options.accountId = this.id;
+
+    return this._jmap.getMailboxes(options);
+  }
+
+  /**
+   * Creates a JSON representation from this {@link Account}.
+   *
+   * @return JSON object with only owned properties and non-null default values.
+   */
+  toJSONObject() {
+    return new JSONBuilder()
+      .append('name', this.name)
+      .append('isPrimary', this.isPrimary)
+      .append('isReadOnly', this.isReadOnly)
+      .append('hasDataFor', this.hasDataFor)
+      .build();
+  }
+
+  /**
+   * Creates an _Account_ from its JSON representation.
+   *
+   * @param jmap {Client} The {@link Client} instance passed to the _Account_ constructor.
+   * @param object {Object} The JSON representation of the _Account_, as a Javascript object.
+   * @param object.id {String} The identifier of the _Account_.
+   *
+   * @return {Account}
+   */
+  static fromJSONObject(jmap, object) {
+    Utils.assertRequiredParameterIsPresent(object, 'object');
+
+    return new Account(jmap, object.id, object);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_Attachment.js.html b/doc/api/models_Attachment.js.html new file mode 100644 index 0000000..69260e9 --- /dev/null +++ b/doc/api/models_Attachment.js.html @@ -0,0 +1,161 @@ + + + + + JSDoc: Source: models/Attachment.js + + + + + + + + + + +
+ +

Source: models/Attachment.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import Utils from '../utils/Utils.js';
+import JSONBuilder from '../utils/JSONBuilder.js';
+
+export default class Attachment extends Model {
+  /**
+   * This class represents a JMAP [Attachment]{@link http://jmap.io/spec.html#messages}.<br />
+   * An _Attachment_ object holds all information of a given attachment of a {@link Message}.
+   *
+   * @constructor
+   * @extends Model
+   *
+   * @param jmap {Client} The {@link Client} instance that created the parent _Message_.
+   * @param blobId {String} The id of the binary data.
+   * @param [opts] {Object} The optional properties of this _Attachment_.
+   * @param [opts.url=null] {String} The URL to download the attachment. If not passed as a parameter, this will be deduced from
+   *  the configured `downloadUrl` of the {@link Client} instance used to fetch the {@link Message} containing this _Attachment_.
+   *  If the library does not find a reliable way of knowing the URL for this attachment, for any reason, the `url` property of this
+   *  _Attachment_ instance will be set to `null`.
+   * @param [opts.type=''] {String} The content-type of the attachment.
+   * @param [opts.name=''] {String} The full file name.
+   * @param [opts.size=null] {Number} The size, in bytes, of the attachment when fully decoded.
+   * @param [opts.cid=null] {String} The id used within the message body to reference this attachment.
+   * @param [opts.isInline=false] {String} `true` if the attachment is referenced by a `cid:` link from within the HTML body of the message.
+   * @param [opts.width=null] {String} The width (in px) of the image, if the attachment is an image.
+   * @param [opts.height=null] {String} TThe height (in px) of the image, if the attachment is an image.
+   *
+   * @see Model
+   */
+  constructor(jmap, blobId, opts) {
+    super(jmap);
+
+    Utils.assertRequiredParameterIsPresent(blobId, 'blobId');
+
+    opts = opts || {};
+
+    this.blobId = blobId;
+    this.type = opts.type || null;
+    this.name = opts.name || null;
+    this.size = opts.size || 0;
+    this.cid = opts.cid || null;
+    this.isInline = opts.isInline || false;
+    this.width = opts.width || null;
+    this.height = opts.height || null;
+    this.url = opts.url || null;
+
+    // Some JMAP servers might return an already defined attachment URL, some others don't; the spec is vague about that
+    // If it is not provided by the server, we do a best effort to derive it from the configured download URL of our client
+    if (!this.url && jmap.downloadUrl) {
+      this.url = Utils.fillURITemplate(jmap.downloadUrl, {
+        blobId: this.blobId,
+        name: this.name || this.blobId
+      });
+    }
+  }
+
+  /**
+   * Gets a signed download URL for this {@link Attachment}.
+   * Details of this process can be found in [the spec](http://jmap.io/spec.html#downloading-an-attachment-through-a-signed-request).
+   * <br />
+   * This mandates that `url` is defined on this {@link Attachment} instance, otherwise we cannot get a signed URL.
+   *
+   * @returns {Promise} A {@link Promise} eventually resolving to the signed download URL.
+   *
+   * @throws {Error} If this `Attachment` instance has no URL available.
+   */
+  getSignedDownloadUrl() {
+    Utils.assertRequiredParameterIsPresent(this.url, 'url');
+
+    return this._jmap.transport
+      .post(this.url, this._jmap._defaultHeaders(), null, true)
+      .then(Utils.appendQueryParameter.bind(null, this.url, 'access_token'));
+  }
+
+  /**
+   * Creates a JSON representation from this model.
+   *
+   * @return JSON object with only owned properties and non default values.
+   */
+  toJSONObject() {
+    return new JSONBuilder()
+      .appendIfDefined('blobId', this.blobId)
+      .appendIfDefined('type', this.type)
+      .appendIfDefined('name', this.name)
+      .appendIfDefined('size', this.size)
+      .appendIfDefined('cid', this.cid)
+      .appendIfDefined('width', this.width)
+      .appendIfDefined('height', this.height)
+      .appendIfDefined('url', this.url)
+      .appendIfDefined('isInline', this.isInline)
+      .build();
+  }
+
+  /**
+   * Creates an _Attachment_ from its JSON representation.
+   *
+   * @param jmap {Client} The {@link Client} instance used to fetch the parent {@link Message}.
+   * @param object {Object} The JSON representation of the _Attachment_, as a Javascript object.
+   * @param object.blobId {String} The id of the binary data for this _Attachment_.
+   *
+   * @return {Attachment}
+   */
+  static fromJSONObject(jmap, object) {
+    Utils.assertRequiredParameterIsPresent(object, 'object');
+
+    return new Attachment(jmap, object.blobId, object);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_AuthAccess.js.html b/doc/api/models_AuthAccess.js.html new file mode 100644 index 0000000..e197b29 --- /dev/null +++ b/doc/api/models_AuthAccess.js.html @@ -0,0 +1,116 @@ + + + + + JSDoc: Source: models/AuthAccess.js + + + + + + + + + + +
+ +

Source: models/AuthAccess.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import Utils from '../utils/Utils.js';
+import Constants from '../utils/Constants.js';
+import Account from './Account.js';
+import ServerCapabilities from './ServerCapabilities.js';
+import MailCapabilities from './MailCapabilities.js';
+import JSONBuilder from '../utils/JSONBuilder.js';
+
+export default class AuthAccess extends Model {
+  /**
+   * This class represents a JMAP [Auth Access Response]{@link http://jmap.io/spec-core.html#201-authentication-is-complete-access-token-created}.
+   *
+   * @constructor
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _AuthAccess_.
+   * @param payload {Object} The server response of an auth access request.
+   */
+  constructor(jmap, payload) {
+    super(jmap);
+
+    Utils.assertRequiredParameterIsPresent(payload, 'payload');
+    ['username', 'accessToken', 'signingId', 'signingKey', 'apiUrl', 'eventSourceUrl', 'uploadUrl', 'downloadUrl', 'accounts', 'capabilities'].forEach((property) => {
+      Utils.assertRequiredParameterIsPresent(payload[property], property);
+    });
+
+    this.username = payload.username;
+    this.accessToken = payload.accessToken;
+    this.signingId = payload.signingId;
+    this.signingKey = payload.signingKey;
+    this.apiUrl = payload.apiUrl;
+    this.eventSourceUrl = payload.eventSourceUrl;
+    this.uploadUrl = payload.uploadUrl;
+    this.downloadUrl = payload.downloadUrl;
+    this.capabilities = payload.capabilities;
+    this.serverCapabilities = new ServerCapabilities(this.capabilities[Constants.CORE_CAPABILITIES_URI] || {});
+    this.mailCapabilities = new MailCapabilities(this.capabilities[Constants.MAIL_CAPABILITIES_URI] || {});
+
+    this.accounts = {};
+    for (var accountId in payload.accounts) {
+      this.accounts[accountId] = Account.fromJSONObject(jmap, Object.assign({ id: accountId }, payload.accounts[accountId]));
+    }
+  }
+
+  /**
+   * Creates a JSON representation from this {@link AuthAccess}.
+   *
+   * @return JSON object with only owned properties and non-null default values.
+   */
+  toJSONObject() {
+    return new JSONBuilder()
+      .append('username', this.username)
+      .append('accessToken', this.accessToken)
+      .append('signingId', this.signingId)
+      .append('signingKey', this.signingKey)
+      .append('apiUrl', this.apiUrl)
+      .append('eventSourceUrl', this.eventSourceUrl)
+      .append('uploadUrl', this.uploadUrl)
+      .append('downloadUrl', this.downloadUrl)
+      .appendObject('accounts', this.accounts)
+      .appendObject('capabilities', this.capabilities)
+      .build();
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_AuthContinuation.js.html b/doc/api/models_AuthContinuation.js.html new file mode 100644 index 0000000..b79024d --- /dev/null +++ b/doc/api/models_AuthContinuation.js.html @@ -0,0 +1,119 @@ + + + + + JSDoc: Source: models/AuthContinuation.js + + + + + + + + + + +
+ +

Source: models/AuthContinuation.js

+ + + + + + +
+
+
'use strict';
+
+import Utils from '../utils/Utils.js';
+import AuthMethod from './AuthMethod';
+
+export default class AuthContinuation {
+  /**
+   * This class represents a JMAP [Auth Continuation Response]{@link http://jmap.io/spec.html#authentication}.
+   *
+   * @constructor
+   *
+   * @param payload {Object} The server response of an initial auth request.
+   */
+  constructor(payload) {
+    Utils.assertRequiredParameterIsPresent(payload, 'payload');
+    Utils.assertRequiredParameterIsPresent(payload.loginId, 'loginId');
+    Utils.assertRequiredParameterIsArrayWithMinimumLength(payload.methods, 'methods');
+
+    this.loginId = payload.loginId;
+    this.methods = payload.methods.map((method) => new AuthMethod(method));
+    this.prompt = payload.prompt || null;
+  }
+
+  /**
+   * Getter for the AuthMethod instance matching the given authentication type
+   *
+   * @param type {String} The authentication type
+   * @return {AuthMethod}
+   */
+  getMethod(type) {
+    Utils.assertRequiredParameterHasType(type, 'type', 'string');
+
+    let result = null;
+
+    this.methods.forEach((authMethod) => {
+      if (authMethod.type === type) {
+        result = authMethod;
+      }
+    });
+
+    if (!result) {
+      throw new Error('No AuthMethod of type "' + type + '" found');
+    }
+
+    return result;
+  }
+
+  /**
+   * Checks if the given authentication type is supported by one of the registred auth methods
+   *
+   * @param type {String} The authentication type to check
+   * @return {Boolean} True if supported, False otherwise
+   */
+  supports(type) {
+    Utils.assertRequiredParameterHasType(type, 'type', 'string');
+
+    let result = false;
+
+    try {
+      this.getMethod(type);
+      result = true;
+    } catch (e) {
+    }
+
+    return result;
+  }
+
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_AuthMethod.js.html b/doc/api/models_AuthMethod.js.html new file mode 100644 index 0000000..8800de0 --- /dev/null +++ b/doc/api/models_AuthMethod.js.html @@ -0,0 +1,71 @@ + + + + + JSDoc: Source: models/AuthMethod.js + + + + + + + + + + +
+ +

Source: models/AuthMethod.js

+ + + + + + +
+
+
'use strict';
+
+import Utils from '../utils/Utils.js';
+
+export default class AuthMethod {
+  /**
+   * This class represents a JMAP [AuthMethod]{@link http://jmap.io/spec.html#getting-an-access-token}.
+   *
+   * @constructor
+   *
+   * @param payload {Object} The server response of POST request to the authentication URL.
+   */
+
+  constructor(payload) {
+    Utils.assertRequiredParameterIsPresent(payload, 'payload');
+    Utils.assertRequiredParameterHasType(payload.type, 'type', 'string');
+
+    Object.assign(this, payload);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_Capabilities.js.html b/doc/api/models_Capabilities.js.html new file mode 100644 index 0000000..704dd00 --- /dev/null +++ b/doc/api/models_Capabilities.js.html @@ -0,0 +1,71 @@ + + + + + JSDoc: Source: models/Capabilities.js + + + + + + + + + + +
+ +

Source: models/Capabilities.js

+ + + + + + +
+
+
'use strict';
+
+import Utils from '../utils/Utils.js';
+
+export default class Capabilities {
+  /**
+   * This class represents an generic JMAP "capabilities" object. See {@link http://jmap.io/spec-core.html#getting-an-access-token*}.<br />
+   *
+   * @param namespace {String} The namespace/identifier of the capabilities.
+   * @param [opts] {Object} The optional properties of this _Capabilities_.
+   */
+  constructor(namespace, opts) {
+    Utils.assertRequiredParameterIsPresent(namespace, 'namespace');
+
+    opts = opts || {};
+
+    this.ns = namespace;
+    Object.assign(this, opts);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_CreateMessageAck.js.html b/doc/api/models_CreateMessageAck.js.html new file mode 100644 index 0000000..9606ddf --- /dev/null +++ b/doc/api/models_CreateMessageAck.js.html @@ -0,0 +1,85 @@ + + + + + JSDoc: Source: models/CreateMessageAck.js + + + + + + + + + + +
+ +

Source: models/CreateMessageAck.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import Utils from '../utils/Utils.js';
+
+export default class CreateMessageAck extends Model {
+  /**
+   * This class should be used to wrap a create response item from a setMessages request.<br />
+   *
+   * @constructor
+   * @extends Model
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _OutboundMessage_.
+   * @param response {Object} The raw created response object.
+   * @param response.blobId {String} The server side generated blobId of the created message.
+   * @param response.size {Number} The server side size of the created message.
+   * @param [response.id=null] {String} The server side generated message id of the created message.
+   * @param [response.threadId=null] {String} The server side assigned threadId of the created message.
+   *
+   * @see Model
+   */
+  constructor(jmap, response) {
+    super(jmap);
+    Utils.assertRequiredParameterIsObject(response, 'response');
+    Utils.assertRequiredParameterIsPresent(response.blobId, 'response.blobId');
+    Utils.assertRequiredParameterHasType(response.size, 'response.size', 'number');
+
+    this.id = response.id;
+    this.blobId = response.blobId;
+    this.size = response.size;
+    this.threadId = response.threadId;
+  }
+
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_EMailer.js.html b/doc/api/models_EMailer.js.html new file mode 100644 index 0000000..1610b71 --- /dev/null +++ b/doc/api/models_EMailer.js.html @@ -0,0 +1,90 @@ + + + + + JSDoc: Source: models/EMailer.js + + + + + + + + + + +
+ +

Source: models/EMailer.js

+ + + + + + +
+
+
'use strict';
+
+export default class EMailer {
+  /**
+   * This class represents a JMAP [EMailer]{@link http://jmap.io/spec.html#messages}.<br />
+   * An _EMailer_ object holds the name and email address of either a sender or a recipient of a {@link Message}.
+   *
+   * @param [opts] {Object} The optional properties of this _EMailer_.
+   * @param [opts.name=''] {String} The name of the emailer.
+   * @param [opts.email='@'] {String} The email address of the emailer.
+   */
+  constructor(opts) {
+    opts = opts || {};
+
+    this.name = opts.name || '';
+    this.email = opts.email || '@'; // http://jmap.io/spec.html#messages
+  }
+
+  /**
+   * This method returns the unknown _EMailer_, that is, an _EMailer_ instance with all fields set to defaults.
+   *
+   * @return {EMailer} The unknown _EMailer_.
+   */
+  static unknown() {
+    return new EMailer();
+  }
+
+  /**
+   * Creates a _EMailer_ from its JSON representation.
+   *
+   * @param jmap {Client} The {@link Client} instance that originates the _EMailer_ instance. Is actually ignored.
+   * @param object {Object} The JSON representation of the _EMailer_, as a Javascript object
+   *
+   * @return {EMailer}
+   */
+  static fromJSONObject(jmap, object) {
+    return new EMailer(object);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_FilterRule.js.html b/doc/api/models_FilterRule.js.html new file mode 100644 index 0000000..4c1e246 --- /dev/null +++ b/doc/api/models_FilterRule.js.html @@ -0,0 +1,138 @@ + + + + + JSDoc: Source: models/FilterRule.js + + + + + + + + + + +
+ +

Source: models/FilterRule.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import uuid from 'uuid/v4';
+import filterRuleConditions from './filterRules/FilterRuleConditions';
+import filterRuleActions from './filterRules/FilterRuleActions';
+import Utils from '../utils/Utils';
+
+class FilterRule extends Model {
+  /**
+   * This class represents a JMAP [FilterRule]{@link http://jmap.io/spec.html}.<br />
+   * The _FilterRule_ object represents the state of incoming message filtering for an account.
+   *
+   * @constructor
+   * @extends Model
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _FilterRule_.
+   * @param name {String} The name of the rule
+   *
+   * NOTE: How to use and extend this model ?
+   *  FilterRule is conceived so that a rule can be specified in a highly didactic way. For instance:
+   *
+   *      new jmap.FilterRule(client, 'My filter')
+   *        .when.from
+   *          .value('admin@open-paas.org')
+   *          .comparator(jmap.FilterRule.Comparator.EXACTLY_EQUALS)
+   *        .then.moveTo
+   *          .mailboxId('36e4d1c0-a473-11e8-aa26-bfb5d32a28f6');
+   *
+   *  To achive this, it uses the builder design pattern. To extend this model with new actions and conditions,
+   *  you just need to create a new class that extends AbstractConditionAction and implements
+   *  AbstractConditionAction#_init and AbstractConditionAction#_toJSONObject.
+   *
+   *  AbstractConditionAction#_init is called by AbstractConditionAction' constructor and
+   *  AbstractConditionAction#_toJSONObject is used to generate a JSON representation of the object.
+   *  Then, just provide any useful property.
+   *
+   *  To make the new condition or action available to the builder, you need to extend FilterRuleCondition
+   *  (if defining a new condition) or FilterRuleAction (if defining a new action)
+   *
+   * @see Model
+   */
+  constructor(jmap, name) {
+    super(jmap);
+
+    this.id = uuid();
+    this.name = name;
+    this.filterCondition = null;
+    this.filterAction = null;
+  }
+
+  get then() {
+    return filterRuleActions(this);
+  }
+
+  get when() {
+    return filterRuleConditions(this);
+  }
+
+  toJSONObject() {
+    Utils.assertRequiredParameterIsPresent(this.filterCondition, '', `Filter must have a condition. Use 'when'.`);
+    Utils.assertRequiredParameterIsPresent(this.filterAction, '', `Filter must have an action. Use 'then'.`);
+    this.filterCondition._validate();
+    this.filterAction._validate();
+
+    return {
+      id: this.id,
+      name: this.name,
+      condition: this.filterCondition._toJSONObject(),
+      action: this.filterAction._toJSONObject()
+    };
+  }
+
+  static fromJSONObject(jmap, object) {
+    throw new Error('Not implemented');
+  }
+}
+
+FilterRule.ID = 'singleton';
+FilterRule.Comparator = Object.freeze({
+  CONTAINS: 'contains',
+  NOT_CONTAINS: 'not-contains',
+  EXACTLY_EQUALS: 'exactly-equals',
+  NOT_EXACTLY_EQUALS: 'not-exactly-equals'
+});
+
+export default FilterRule;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_MailCapabilities.js.html b/doc/api/models_MailCapabilities.js.html new file mode 100644 index 0000000..c5f7efb --- /dev/null +++ b/doc/api/models_MailCapabilities.js.html @@ -0,0 +1,85 @@ + + + + + JSDoc: Source: models/MailCapabilities.js + + + + + + + + + + +
+ +

Source: models/MailCapabilities.js

+ + + + + + +
+
+
'use strict';
+
+import Capabilities from './Capabilities';
+import Constants from '../utils/Constants';
+
+export default class MailCapabilities extends Capabilities {
+  /**
+   * This class represents a JMAP [MailCapabilities]{@link http://jmap.io/spec.html#accounts*}.<br />
+   * An _MailCapabilities_ object describes mail-related capabilities of a JMAP server.
+   *
+   * @constructor
+   * @extends Capabilities
+   *
+   * @param [opts] {Object} The optional properties of this _MailCapabilities_.
+   * @param [opts.maxMailboxesPerMessage=null] {Number} The maximum number of mailboxes that can be can assigned to a single message.
+   * @param [opts.maxSizeMessageAttachments=0] {Number} The maximum total size of attachments, in bytes, allowed for messages.
+   * @param [opts.maxDelayedSend=0] {Number} The number in seconds of the maximum delay the server supports in sending. 0 if delayed send is not supported.
+   * @param [opts.messageListSortOptions=[]] {String[]} A list of all the message properties the server supports for sorting by.
+   * @param [opts.submissionExtensions={} {String[String[]]} Known safe-to-expose EHLO capabilities of the submission server.
+   *
+   * @see Capabilities
+   */
+  constructor(opts) {
+    opts = opts || {};
+
+    super(Constants.MAIL_CAPABILITIES_URI);
+
+    this.maxMailboxesPerMessage = opts.maxMailboxesPerMessage || null;
+    this.maxSizeMessageAttachments = opts.maxSizeMessageAttachments || 0;
+    this.maxDelayedSend = opts.maxDelayedSend || 0;
+    this.messageListSortOptions = opts.messageListSortOptions || [];
+    this.submissionExtensions = opts.submissionExtensions || {};
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_Mailbox.js.html b/doc/api/models_Mailbox.js.html new file mode 100644 index 0000000..41e9424 --- /dev/null +++ b/doc/api/models_Mailbox.js.html @@ -0,0 +1,184 @@ + + + + + JSDoc: Source: models/Mailbox.js + + + + + + + + + + +
+ +

Source: models/Mailbox.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import Utils from '../utils/Utils.js';
+import MailboxRole from './MailboxRole.js';
+
+export default class Mailbox extends Model {
+  /**
+   * This class represents a JMAP [Mailbox]{@link http://jmap.io/spec.html#mailboxes}.
+   *
+   * @constructor
+   * @extends Model
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _Mailbox_.
+   * @param id {String} The unique identifier of this _Mailbox_.
+   * @param name {String} The user-visible name (i.e.: display name) of this _Mailbox_.
+   * @param [opts] {Object} The optional properties of this _Mailbox_.
+   * @param [opts.namespace={}] {Object} The namespace give information about mailbox type and owner.
+   * @param [opts.parentId=null] {String} The _Mailbox_ id for the parent of this mailbox, or _null_ if this mailbox is at the top level.
+   * @param [opts.role=null] {String} The role of this mailbox, if it is a system mailbox. See the specification for the possible values.
+   * @param [opts.sharedWith={}] {Object} The sharedWith give information about mailbox shared and rights.
+   * @param [opts.sortOrder=0] {String} Defines the sort order of mailboxes when presented in the UI.
+   * @param [opts.mustBeOnlyMailbox=false] {Boolean} If _true_, messages in this mailbox may not also be in any other mailbox.
+   * @param [opts.mayReadItems=false] {Boolean}  If _true_, may use this mailbox as part of a filter in a {@link Client#getMessageList} call.
+   * @param [opts.mayAddItems=false] {Boolean} If _true_, the user may add messages to this mailbox.
+   * @param [opts.mayRemoveItems=false] {Boolean} If _true_, the user may remove messages from this mailbox.
+   * @param [opts.mayCreateChild=false] {Boolean} If _true_, the user may create a _Mailbox_ with this _Mailbox_ as its parent.
+   * @param [opts.mayRename=false] {Boolean} If _true_, the user may rename this mailbox or make it a child of another mailbox.
+   * @param [opts.mayDelete=false] {Boolean} If _true_, the user may delete this mailbox.
+   * @param [opts.totalMessages=0] {Number} The number of messages in this mailbox.
+   * @param [opts.unreadMessages=0] {Number} The number of messages in this mailbox with _isUnread_=true and _isDraft_=false.
+   * @param [opts.totalThreads=0] {Number} The number of threads where at least one message in the thread is in this mailbox.
+   * @param [opts.unreadThreads=0] {Number} The number of threads where at least one message in the thread is in this mailbox with _isUnread_=true and _isDraft_=false.
+   * @param [opts.quotas={}] {Object} List of enforced quotas. 'STORAGE' for size quota and 'MESSAGE' for messages count. Each one provide used and max properties.
+       used (Number) number of messages, or size in bytes for storage
+       max (Number|null) maximum number of messages, or maximum size in bytes for storage. Null means unlimited
+   * @see Model
+   */
+  constructor(jmap, id, name, opts) {
+    super(jmap);
+
+    Utils.assertRequiredParameterIsPresent(id, 'id');
+    Utils.assertRequiredParameterIsPresent(name, 'name');
+
+    opts = opts || {};
+
+    this.id = id;
+    this.name = name;
+    this.namespace = opts.namespace || {};
+    this.parentId = opts.parentId || null;
+    this.role = MailboxRole.fromRole(opts.role);
+    this.sharedWith = opts.sharedWith || {};
+    this.sortOrder = opts.sortOrder || 0;
+    this.mustBeOnlyMailbox = opts.mustBeOnlyMailbox || false;
+    this.mayReadItems = opts.mayReadItems || false;
+    this.mayAddItems = opts.mayAddItems || false;
+    this.mayRemoveItems = opts.mayRemoveItems || false;
+    this.mayCreateChild = opts.mayCreateChild || false;
+    this.mayRename = opts.mayRename || false;
+    this.mayDelete = opts.mayDelete || false;
+    this.totalMessages = opts.totalMessages || 0;
+    this.unreadMessages = opts.unreadMessages || 0;
+    this.totalThreads = opts.totalThreads || 0;
+    this.unreadThreads = opts.unreadThreads || 0;
+    this.quotas = opts.quotas || {};
+  }
+
+  /**
+   * Fetches a message list from this _Mailbox_.<br />
+   * This will delegate to {@link Client#getMessageList}, passing the following filter:
+   *
+   *     {
+   *       inMailboxes: [<this Mailbox id>]
+   *     }
+   *
+   * @param [options] {Object} The options object passed to {@link Client#getMessageList}.
+   *   Please note that the _filter_ option will be overriden if defined.
+   * @returns {Promise} A promise that eventually resolves with a {@link MessageList} instance.
+   *
+   * @see Client#getMessageList
+   * @see PromiseProvider
+   */
+  getMessageList(options) {
+    options = options || {};
+    options.filter = {
+      inMailboxes: [this.id]
+    };
+
+    return this._jmap.getMessageList(options);
+  }
+
+  /**
+   * Update this {@link Mailbox}.
+   *
+   * @param options {Object} The attribute to be updated in this {@link Mailbox}.
+   * @param options.name {String} The user-visible name of the _Mailbox_.
+   * @param [options.parentId = null] {String} The _Mailbox_ id for the parent of this mailbox, or _null_ if this mailbox is at the top level.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.updateMailbox}.
+   *
+   * @see Client#updateMailbox
+   */
+  update(options) {
+    return this._jmap.updateMailbox(this.id, options);
+  }
+
+  /**
+   * Destroy this {@link Mailbox} on the server.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.destroyMailbox}.
+   *
+   * @see Client#destroyMailbox
+   */
+  destroy() {
+    return this._jmap.destroyMailbox(this.id);
+  }
+
+  /**
+   * Creates a _Mailbox_ from its JSON representation.
+   *
+   * @param jmap {Client} The {@link Client} instance passed to the _Mailbox_ constructor.
+   * @param object {Object} The JSON representation of the _Mailbox_, as a Javascript object.
+   * @param object.id {String} The identifier of the _Mailbox_.
+   * @param object.name {String} The user-visible name of the _Mailbox_.
+   *
+   * @return {Mailbox}
+   */
+  static fromJSONObject(jmap, object) {
+    Utils.assertRequiredParameterIsPresent(object, 'object');
+
+    return new Mailbox(jmap, object.id, object.name, object);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_MailboxRole.js.html b/doc/api/models_MailboxRole.js.html new file mode 100644 index 0000000..328c779 --- /dev/null +++ b/doc/api/models_MailboxRole.js.html @@ -0,0 +1,95 @@ + + + + + JSDoc: Source: models/MailboxRole.js + + + + + + + + + + +
+ +

Source: models/MailboxRole.js

+ + + + + + +
+
+
'use strict';
+
+class MailboxRole {
+  /**
+   * The MailboxRole class is simply a holder for predefined JMAP mailbox roles.<br />
+   * It exposes class constants for every predefined roles (trash, inbox, etc.)
+   *
+   * @constructor
+   *
+   * @param role {String} The JMAP mailbox role. This is exposed as the `value` property.
+   *
+   * @see http://jmap.io/spec.html#mailboxes
+   */
+  constructor(role) {
+    this.value = role;
+  }
+
+  /**
+   * Returns the class constant mapping to the given JMAP role, or {@link MailboxRole.UNKNOWN}
+   * if the role is undefined, null or isn't a predefined role.
+   *
+   * @param role {String} The JMAP role to find the {@link MailboxRole} for.
+   *
+   * @return {MailboxRole}
+   */
+  static fromRole(role) {
+    if (role) {
+      for (let key in MailboxRole) {
+        if (MailboxRole.hasOwnProperty(key) && MailboxRole[key].value === role) {
+          return MailboxRole[key];
+        }
+      }
+    }
+
+    return MailboxRole.UNKNOWN;
+  }
+}
+
+['inbox', 'archive', 'drafts', 'outbox', 'sent', 'trash', 'spam', 'templates'].forEach((role) => {
+  MailboxRole[role.toUpperCase()] = new MailboxRole(role);
+});
+MailboxRole.UNKNOWN = new MailboxRole(null);
+
+export default MailboxRole;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_Message.js.html b/doc/api/models_Message.js.html new file mode 100644 index 0000000..2f9228b --- /dev/null +++ b/doc/api/models_Message.js.html @@ -0,0 +1,251 @@ + + + + + JSDoc: Source: models/Message.js + + + + + + + + + + +
+ +

Source: models/Message.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import EMailer from './EMailer.js';
+import Utils from '../utils/Utils.js';
+import Attachment from './Attachment.js';
+
+export default class Message extends Model {
+  /**
+   * This class represents a JMAP [Message]{@link http://jmap.io/spec.html#messages}.<br />
+   * When creating a new _Message_ instance, the following requirements must be met:
+   *   * The _threadId_ must be defined (in JMAP, a _Message_ is always in a _Thread_)
+   *   * The _mailboxIds_ must contain at least one element.
+   *
+   * @constructor
+   * @extends Model
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _Message_.
+   * @param id {String} The unique identifier of this _Message_.
+   * @param blobId {String} The identifier  representing the raw [@!RFC5322] message.
+   * @param threadId {String} The unique identifier of the _Thread_ this _Message_ is in.
+   * @param mailboxIds {String[]} The array of _Mailbox_ identifiers this _Message_ is present into.
+   * @param [opts] {Object} The optional properties of this _Message_.
+   * @param [opts.inReplyToMessageId=null] {String} The id of the _Message_ this _Message_ is a reply to.
+   * @param [opts.isUnread=false] {Boolean} Has the message not yet been read? This maps to the opposite of the \Seen flag in IMAP.
+   * @param [opts.isFlagged=false] {Boolean} Is the message flagged? This maps to the \Flagged flag in IMAP.
+   * @param [opts.isAnswered=false] {Boolean} Has the message been replied to? This maps to the \Answered flag in IMAP.
+   * @param [opts.isForwarded=false] {Boolean} Has the message been forwarded ?.
+   * @param [opts.isDraft=false] {Boolean} Is the message a draft? This maps to the \Draft flag in IMAP.
+   * @param [opts.hasAttachment=false] {Boolean} Does the message have any attachments?
+   * @param [opts.headers] {Object} A hash of header name to header value for all headers in the message.
+   *   For headers that occur multiple times, the values are concatenated with a single new line (\n) character in between each one.
+   * @param [opts.from=null] {EMailer} The {@link EMailer} object representing the first identified sender of this _Message_.
+   * @param [opts.to=[{@link EMailer.unknown}]] {EMailer[]} The array of {@link EMailer} objects representing the _To:_ of this _Message_.
+   * @param [opts.cc=[{@link EMailer.unknown}]] {EMailer[]} The array of {@link EMailer} objects representing the _CC:_ of this _Message_.
+   * @param [opts.bcc=[{@link EMailer.unknown}]] {EMailer[]} The array of {@link EMailer} objects representing the _BCC:_ of this _Message_.
+   * @param [opts.replyTo={@link EMailer.unknown}] {EMailer[]} The array of {@link EMailer} objects representing the _Reply-To:_ of this _Message_.
+   * @param [opts.subject=null] {String} The subject of this _Message_.
+   * @param [opts.date=null] {Date} The date the _Message_ was sent (or saved, if the message is a draft).
+   * @param [opts.size=0] {String} The size in bytes of the whole message as counted by the server.
+   * @param [opts.preview=null] {String} Up to 256 characters of the beginning of a plain text version of the _Message_ body.
+   * @param [opts.textBody=null] {String} The plain text body part for the _Message_.
+   * @param [opts.htmlBody=null] {String} The HTML body part for the _Message_, if present.
+   * @param [opts.attachments=[]] {Attachment[]} An array of {@link Attachment} objects detailing all the attachments to the message.
+   *
+   * @see Model
+   * @see EMailer
+   */
+  constructor(jmap, id, blobId, threadId, mailboxIds, opts) {
+    super(jmap);
+
+    Utils.assertRequiredParameterIsPresent(id, 'id');
+    Utils.assertRequiredParameterIsPresent(blobId, 'blobId');
+    Utils.assertRequiredParameterIsPresent(threadId, 'threadId');
+    Utils.assertRequiredParameterIsArrayWithMinimumLength(mailboxIds, 'mailboxIds', 1);
+
+    opts = opts || {};
+
+    this.id = id;
+    this.blobId = blobId;
+    this.threadId = threadId;
+    this.mailboxIds = mailboxIds;
+    this.inReplyToMessageId = opts.inReplyToMessageId || null;
+    this.isUnread = opts.isUnread || false;
+    this.isFlagged = opts.isFlagged || false;
+    this.isAnswered = opts.isAnswered || false;
+    this.isForwarded = opts.isForwarded || false;
+    this.isDraft = opts.isDraft || false;
+    this.hasAttachment = opts.hasAttachment || false;
+    this.headers = opts.headers || {};
+    this.from = Utils._jsonArrayToModelList(jmap, EMailer, Array.isArray(opts.from) ? opts.from : [opts.from])[0];
+    this.to = Utils._jsonArrayToModelList(jmap, EMailer, opts.to);
+    this.cc = Utils._jsonArrayToModelList(jmap, EMailer, opts.cc);
+    this.bcc = Utils._jsonArrayToModelList(jmap, EMailer, opts.bcc);
+    this.replyTo = opts.replyTo || [];
+    this.subject = opts.subject || null;
+    this.date = opts.date ? new Date(opts.date) : null;
+    this.size = opts.size || 0;
+    this.preview = opts.preview || null;
+    this.textBody = opts.textBody || null;
+    this.htmlBody = opts.htmlBody || null;
+    this.attachments = Utils._jsonArrayToModelList(jmap, Attachment, opts.attachments);
+  }
+
+  /**
+   * Moves this {@link Message} to a different set of mailboxes.
+   *
+   * @param mailboxIds {String[]} The identifiers of the target mailboxes for the message.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.moveMessage}.
+   *
+   * @see Client#moveMessage
+   */
+  move(mailboxIds) {
+    return this._jmap.moveMessage(this.id, mailboxIds);
+  }
+
+  /**
+   * Moves this {@link Message} to the mailbox holding the given `role`.<br />
+   * This will first do a JMAP request to find the mailbox with the given role, then a {@link Message#move} to move the message.
+   *
+   * @param role {MailboxRole|String} The desired mailbox role.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Message#move}.
+   *
+   * @see MailboxRole
+   * @see Client#getMailboxWithRole
+   */
+  moveToMailboxWithRole(role) {
+    return this._jmap.getMailboxWithRole(role)
+      .then((mailbox) => this.move([mailbox.id]));
+  }
+
+  /**
+   * Updates this {@link Message}.
+   *
+   * @param options {Object} The options to be updated in this {@link Message} as per {@link Client.updateMessage}.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.updateMessage}.
+   *
+   * @see Client#updateMessage
+   */
+  update(options) {
+    return this._jmap.updateMessage(this.id, options);
+  }
+
+  /**
+   * Updates the isFlagged field of this {@link Message}.
+   *
+   * @param isFlagged {Boolean} The isFlagged field of the message.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.updateMessage}.
+   *
+   * @see Client#updateMessage
+   */
+  setIsFlagged(isFlagged) {
+    Utils.assertRequiredParameterHasType(isFlagged, 'isFlagged', 'boolean');
+
+    return this.update({ isFlagged: isFlagged });
+  }
+
+  /**
+   * Updates the isUnread field of this {@link Message}.
+   *
+   * @param isUnread {Boolean} The isUnread field of the message.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.updateMessage}.
+   *
+   * @see Client#updateMessage
+   */
+  setIsUnread(isUnread) {
+    Utils.assertRequiredParameterHasType(isUnread, 'isUnread', 'boolean');
+
+    return this.update({ isUnread: isUnread });
+  }
+
+  /**
+   * Updates the isAnswered field of this {@link Message}.
+   *
+   * @param isAnswered {Boolean} The isAnswered field of the message.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.updateMessage}.
+   *
+   * @see Client#updateMessage
+   */
+  setIsAnswered(isAnswered) {
+    Utils.assertRequiredParameterHasType(isAnswered, 'isAnswered', 'boolean');
+
+    return this.update({ isAnswered: isAnswered });
+  }
+
+  /**
+   * Destroy this {@link Message} on the server.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.destroyMessage}.
+   *
+   * @see Client#destroyMessage
+   */
+  destroy() {
+    return this._jmap.destroyMessage(this.id);
+  }
+
+  /**
+   * Creates a _Message_ from its JSON representation.
+   *
+   * @param jmap {Client} The {@link Client} instance passed to the _Message_ constructor.
+   * @param object {Object} The JSON representation of the _Message_, as a Javascript object.
+   * @param object.id {Object} The identifier of the _Message_.
+   * @param object.blobId {String} The identifier  representing the raw [@!RFC5322] message.
+   * @param object.threadId {String} The identifier of the thread the _Message_ is in.
+   * @param object.mailboxIds {String[]} The array of _Mailbox_ identifiers the _Message_ is present into.
+   *
+   * @return {Message}
+   */
+  static fromJSONObject(jmap, object) {
+    Utils.assertRequiredParameterIsPresent(object, 'object');
+
+    return new Message(jmap, object.id, object.blobId, object.threadId, object.mailboxIds, object);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_MessageList.js.html b/doc/api/models_MessageList.js.html new file mode 100644 index 0000000..1e72edd --- /dev/null +++ b/doc/api/models_MessageList.js.html @@ -0,0 +1,143 @@ + + + + + JSDoc: Source: models/MessageList.js + + + + + + + + + + +
+ +

Source: models/MessageList.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import Utils from '../utils/Utils.js';
+
+export default class MessageList extends Model {
+  /**
+   * This class represents a JMAP [MessageList]{@link http://jmap.io/spec.html#messagelists}.
+   *
+   * @constructor
+   * @extends Model
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _Mailbox_.
+   * @param [opts] {Object} The optional properties of this _Mailbox_.
+   * @param [opts.accountId=''] {String} The id of the {@link Account} used in the request that originated this _MessageList_.
+   * @param [opts.filter=null] {Object} The filter used in the request that originated this _MessageList_.
+   * @param [opts.sort=null] {Object} The sort properties used in the request that originated this _MessageList_.
+   * @param [opts.collapseThreads=false] {Boolean} The collapseThreads value used in the request that originated this _MessageList_.
+   * @param [opts.position=0] {Number} The 0-based index of the first result in the _threadIds_ array within the complete list.
+   * @param [opts.total=0] {Number} The total number of messages in the message list (given the filter and collapseThreads arguments).
+   * @param [opts.threadIds=[]] {String[]} The list of _Thread_ identifiers for each message in the list after filtering, sorting and collapsing threads.
+   * @param [opts.messageIds=[]] {String[]} The list of _Message_ identifiers for each message in the list after filtering, sorting and collapsing threads.
+   *
+   * @see Model
+   * @see Thread
+   * @see Message
+   */
+  constructor(jmap, opts) {
+    super(jmap);
+
+    opts = opts || {};
+
+    this.accountId = opts.accountId || '';
+    this.filter = opts.filter || null;
+    this.sort = opts.sort || null;
+    this.collapseThreads = opts.collapseThreads || false;
+    this.position = opts.position || 0;
+    this.total = opts.total || 0;
+    this.threadIds = opts.threadIds || [];
+    this.messageIds = opts.messageIds || [];
+  }
+
+  /**
+   * Fetches all threads contained in this _MessageList_.<br />
+   * This will delegate to {@link Client#getThreads}, passing this MessageList's _threadIds_ as the _ids_ option.
+   *
+   * @param [options] {Object} The options object passed to {@link Client#getThreads}.
+   *   Please note that the _ids_ option will be overriden if defined.
+   * @returns {Promise} A promise that eventually resolves with an array of {@link Thread} instances.
+   *
+   * @see Client#getThreads
+   * @see PromiseProvider
+   */
+  getThreads(options) {
+    options = options || {};
+    options.ids = this.threadIds;
+
+    return this._jmap.getThreads(options);
+  }
+
+  /**
+   * Fetches all messages contained in this _MessageList_.<br />
+   * This will delegate to {@link Client#getMessages}, passing this MessageList's _messageIds_ as the _ids_ option.
+   *
+   * @param [options] {Object} The options object passed to {@link Client#getMessages}.
+   *   Please note that the _ids_ option will be overriden if defined.
+   * @returns {Promise} A promise that eventually resolves with an array of {@link Message} instances.
+   *
+   * @see Client#getMessages
+   * @see PromiseProvider
+   */
+  getMessages(options) {
+    options = options || {};
+    options.ids = this.messageIds;
+
+    return this._jmap.getMessages(options);
+  }
+
+  /**
+   * Creates a _MessageList_ from its JSON representation.
+   *
+   * @param jmap {Client} The {@link Client} instance passed to the _MessageList_ constructor.
+   * @param object {Object} The JSON representation of the _MessageList_, as a Javascript object.
+   *
+   * @return {MessageList}
+   */
+  static fromJSONObject(jmap, object) {
+    Utils.assertRequiredParameterIsPresent(object, 'object');
+
+    return new MessageList(jmap, object);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_Model.js.html b/doc/api/models_Model.js.html new file mode 100644 index 0000000..8ead5cc --- /dev/null +++ b/doc/api/models_Model.js.html @@ -0,0 +1,69 @@ + + + + + JSDoc: Source: models/Model.js + + + + + + + + + + +
+ +

Source: models/Model.js

+ + + + + + +
+
+
'use strict';
+
+export default class Model {
+  /**
+   * The base class for all JMAP entities.<br />
+   * When implementing new entities you should always try to inherit from this.<br />
+   * <br />
+   * You shouldn't use this constructor directly, but rather create instances of concrete implementations.
+   *
+   * @constructor
+   * @abstract
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _Model_. This will be exposed as the **_jmap** property.
+   */
+  constructor(jmap) {
+    this._jmap = jmap;
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_OutboundMessage.js.html b/doc/api/models_OutboundMessage.js.html new file mode 100644 index 0000000..350f750 --- /dev/null +++ b/doc/api/models_OutboundMessage.js.html @@ -0,0 +1,139 @@ + + + + + JSDoc: Source: models/OutboundMessage.js + + + + + + + + + + +
+ +

Source: models/OutboundMessage.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import Utils from '../utils/Utils.js';
+import Attachment from './Attachment.js';
+import JSONBuilder from '../utils/JSONBuilder.js';
+
+export default class OutboundMessage extends Model {
+  /**
+   * This class represents a JMAP [Message]{@link http://jmap.io/spec.html#messages} but for client-to-server purpose.<br />
+   * When creating a new _OutboundMessage_ instance, the following requirements must be met:
+   *   * The _id_, _blobId_, _threadId_, _size_, _preview_, _hasAttachment_ and _attachedMessages_ must be not defined (it is set by the server upon creation)
+   *
+   * @constructor
+   * @extends Model
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _OutboundMessage_.
+   * @param [opts] {Object} The optional properties of this _OutboundMessage_.
+   * @param [opts.mailboxIds=[]] {String[]} The array of _Mailbox_ identifiers which will contain this _OutboundMessage_.
+   * @param [opts.inReplyToMessageId=null] {String} The id of the _Message_ this _OutboundMessage_ is a reply to.
+   * @param [opts.isUnread=null] {Boolean} Has the message not yet been read? This maps to the opposite of the \Seen flag in IMAP.
+   * @param [opts.isFlagged=null] {Boolean} Is the message flagged? This maps to the \Flagged flag in IMAP.
+   * @param [opts.isAnswered=null] {Boolean} Has the message been replied to? This maps to the \Answered flag in IMAP.
+   * @param [opts.isDraft=null] {Boolean} Is the message a draft? This maps to the \Draft flag in IMAP.
+   * @param [opts.headers] {Object} A hash of header name to header value for all headers in the message.
+   *   For headers that occur multiple times, the values are concatenated with a single new line (\n) character in between each one.
+   * @param [opts.from=null] {String} Overrides the value used as _From:_ in the headers.
+   * @param [opts.to=null] {String[]} Overrides the value used as _To:_ in the headers.
+   * @param [opts.cc=null] {String[]} Overrides the value used as _CC:_ in the headers.
+   * @param [opts.bcc=null] {String[]} Overrides the value used as _BCC:_ in the headers.
+   * @param [opts.replyTo=null] {String} Overrides the value used as _Reply-To:_ in the headers.
+   * @param [opts.subject=null] {String} The subject of this _OutboundMessage_.
+   * @param [opts.textBody=null] {String} The plain text body part.
+   * @param [opts.htmlBody=null] {String} The HTML body part.
+   * @param [opts.attachments=[]] {Attachment[]} An array of {@link Attachment} objects detailing all the attachments to the message.
+   *   Attachments must first be uploaded using the standard upload mechanism.
+   *
+   * @see Model
+   */
+  constructor(jmap, opts) {
+    super(jmap);
+
+    opts = opts || {};
+
+    this.mailboxIds = opts.mailboxIds || [];
+    this.inReplyToMessageId = opts.inReplyToMessageId || null;
+    this.isUnread = opts.isUnread;
+    this.isFlagged = opts.isFlagged;
+    this.isAnswered = opts.isAnswered;
+    this.isDraft = opts.isDraft;
+    this.headers = opts.headers || null;
+    this.from = opts.from || null;
+    this.to = opts.to || null;
+    this.cc = opts.cc || null;
+    this.bcc = opts.bcc || null;
+    this.replyTo = opts.replyTo || null;
+    this.subject = opts.subject || null;
+    this.textBody = opts.textBody || null;
+    this.htmlBody = opts.htmlBody || null;
+    this.attachments = Utils._jsonArrayToModelList(jmap, Attachment, opts.attachments);
+  }
+
+  /**
+   * Creates a JSON representation from this model.
+   *
+   * @return JSON object with only owned properties and non default values.
+   */
+  toJSONObject() {
+    return new JSONBuilder()
+      .appendIfNotEmpty('mailboxIds', this.mailboxIds)
+      .appendIfDefined('inReplyToMessageId', this.inReplyToMessageId)
+      .appendIfDefined('isUnread', this.isUnread)
+      .appendIfDefined('isFlagged', this.isFlagged)
+      .appendIfDefined('isAnswered', this.isAnswered)
+      .appendIfDefined('isDraft', this.isDraft)
+      .appendIfDefined('headers', this.headers)
+      .appendIfDefined('from', this.from)
+      .appendIfDefined('to', this.to)
+      .appendIfDefined('cc', this.cc)
+      .appendIfDefined('bcc', this.bcc)
+      .appendIfDefined('replyTo', this.replyTo)
+      .appendIfDefined('subject', this.subject)
+      .appendIfDefined('textBody', this.textBody)
+      .appendIfDefined('htmlBody', this.htmlBody)
+      .appendIfNotEmpty('attachments', this.attachments)
+      .build();
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_ServerCapabilities.js.html b/doc/api/models_ServerCapabilities.js.html new file mode 100644 index 0000000..e4e3979 --- /dev/null +++ b/doc/api/models_ServerCapabilities.js.html @@ -0,0 +1,81 @@ + + + + + JSDoc: Source: models/ServerCapabilities.js + + + + + + + + + + +
+ +

Source: models/ServerCapabilities.js

+ + + + + + +
+
+
'use strict';
+
+export default class ServerCapabilities {
+  /**
+   * This class represents a JMAP [ServerCapabilities]{@link http://jmap.io/spec-core.html#201-authentication-is-complete-access-token-created}.<br />
+   * An _ServerCapabilities_ object describes general capabilities of a JMAP server.
+   *
+   * @constructor
+   *
+   * @param [opts] {Object} The optional properties of this _ServerCapabilities_.
+   * @param [opts.maxSizeUpload=0] {Number} The maximum file size, in bytes, that the server will accept for a single file upload.
+   * @param [opts.maxSizeRequest=0] {Number} The maximum size, in bytes, that the server will accept for a single request to the API endpoint.
+   * @param [opts.maxConcurrentUpload=1] {Number} The maximum number of concurrent requests the server will accept to the upload endpoint.
+   * @param [opts.maxConcurrentRequests=1] {Number} The maximum number of concurrent requests the server will accept to the API endpoint.
+   * @param [opts.maxCallsInRequest=1] {Number} The maximum number of method calls the server will accept in a single request to the API endpoint.
+   * @param [opts.maxObjectsInGet=0] {Number} The maximum number of objects that the client may request in a single getXXX type method call.
+   * @param [opts.maxObjectsInSet=0] {Number} The maximum number of objects the client may send to create, update or destroy in a single setXXX type method call.
+   */
+  constructor(opts) {
+    opts = opts || {};
+
+    this.maxSizeUpload = opts.maxSizeUpload || 0;
+    this.maxSizeRequest = opts.maxSizeRequest || 0;
+    this.maxConcurrentUpload = opts.maxConcurrentUpload || 1;
+    this.maxConcurrentRequests = opts.maxConcurrentRequests || 1;
+    this.maxCallsInRequest = opts.maxCallsInRequest || 1;
+    this.maxObjectsInGet = opts.maxObjectsInGet || 0;
+    this.maxObjectsInSet = opts.maxObjectsInSet || 0;
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_SetResponse.js.html b/doc/api/models_SetResponse.js.html new file mode 100644 index 0000000..7cc06c6 --- /dev/null +++ b/doc/api/models_SetResponse.js.html @@ -0,0 +1,126 @@ + + + + + JSDoc: Source: models/SetResponse.js + + + + + + + + + + +
+ +

Source: models/SetResponse.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import Utils from '../utils/Utils.js';
+import JmapError from '../errors/JmapError';
+
+export default class SetResponse extends Model {
+  /**
+   * This class represents a JMAP [xxxSet] {@link http://jmap.io/spec.html#setfoos}.
+   *
+   * @constructor
+   * @extends Model
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _SetResponse_.
+   * @param [opts] {Object} The optional properties of this _SetResponse_.
+   * @param [opts.accountId=''] {String} The id of the {@link Account} used in the request that originated this _SetResponse_.
+   * @param [opts.oldState=''] {String} The state string that would have been returned by _getXXX_ before making the requested changes,
+   *        or null if the server doesn’t know what the previous state string was.
+   * @param [opts.newState=''] {String[]} The state string that will now be returned by _getXXX_.
+   * @param [opts.created=[]] {String[]} A map of the creation id to an object containing any server-assigned properties of
+   *        the _XXX_ object (including the id) for all successfully created records.
+   * @param [opts.updated=[]] {String[]}  A list of _XXX_ ids for records that were successfully updated.
+   * @param [opts.destroyed=[]] {String[]}  A list of _XXX_ ids for records that were successfully destroyed.
+   * @param [opts.MDNSent=[]] {String[]|null}  A list of receipt request ids for receipt that were successfully sent.
+   * @param [opts.notCreated=[]] {String[]} A map of creation id to a SetError object for each _XXX_ that failed to be created.
+   * @param [opts.notUpdated=[]] {String[]} A map of _XXX_ id to a SetError object for each _XXX_ that failed to be updated.
+   * @param [opts.notDestroyed=[]] {String[]} A map of _XXX_ id to a SetError object for each _XXX_ that failed to be destroyed.
+   * @param [opts.MDNNotSent={}] {String[SetError]|null} A map of MDN request id to a SetError object for each receipt that failed to be sent, or null if all successful.
+   *
+   * @see Model
+   */
+  constructor(jmap, opts) {
+    super(jmap);
+
+    opts = opts || {};
+
+    this.accountId = opts.accountId || null;
+    this.oldState = opts.oldState || null;
+    this.newState = opts.newState || '';
+    this.created = opts.created || {};
+    this.updated = opts.updated || [];
+    this.destroyed = opts.destroyed || [];
+    this.MDNSent = opts.MDNSent || [];
+    this.notCreated = SetResponse._mapSetErrorsToJmapErrors(opts.notCreated || {});
+    this.notUpdated = SetResponse._mapSetErrorsToJmapErrors(opts.notUpdated || {});
+    this.notDestroyed = SetResponse._mapSetErrorsToJmapErrors(opts.notDestroyed || {});
+    this.MDNNotSent = SetResponse._mapSetErrorsToJmapErrors(opts.MDNNotSent || {});
+  }
+
+  /**
+   * Creates a _SetResponse_ from its JSON representation.
+   *
+   * @param jmap {Client} The {@link Client} instance passed to the _SetResponse_ constructor.
+   * @param object {Object} The JSON representation of the _SetResponse_, as a Javascript object.
+   *
+   * @return {SetResponse}
+   */
+  static fromJSONObject(jmap, object) {
+    Utils.assertRequiredParameterIsPresent(object, 'object');
+
+    return new SetResponse(jmap, object);
+  }
+
+  static _mapSetErrorsToJmapErrors(errors) {
+    let newErrors = {};
+
+    for (let key in errors) {
+      if (errors.hasOwnProperty(key)) {
+        newErrors[key] = new JmapError(errors[key]);
+      }
+    }
+
+    return newErrors;
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_Thread.js.html b/doc/api/models_Thread.js.html new file mode 100644 index 0000000..798bffd --- /dev/null +++ b/doc/api/models_Thread.js.html @@ -0,0 +1,196 @@ + + + + + JSDoc: Source: models/Thread.js + + + + + + + + + + +
+ +

Source: models/Thread.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import Utils from '../utils/Utils.js';
+
+export default class Thread extends Model {
+  /**
+   * This class represents a JMAP [Thread]{@link http://jmap.io/spec.html#threads}.
+   *
+   * @constructor
+   * @extends Model
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _Thread_.
+   * @param id {String} The unique identifier of this _Thread_.
+   * @param [opts] {Object} The optional properties of this _Thread_.
+   * @param [opts.messageIds=[]] {String[]} An array of message identifiers contained in this _Thread_.
+   *
+   * @see Model
+   */
+  constructor(jmap, id, opts) {
+    super(jmap);
+
+    Utils.assertRequiredParameterIsPresent(id, 'id');
+
+    opts = opts || {};
+
+    this.id = id;
+    this.messageIds = opts.messageIds || [];
+  }
+
+  /**
+   * Fetches all messages contained in this _Thread_.<br />
+   * This will delegate to {@link Client#getMessages}, passing this Thread's _messageIds_ as the _ids_ option.
+   *
+   * @param [options] {Object} The options object passed to {@link Client#getMessages}.
+   *   Please note that the _ids_ option will be overriden if defined.
+   * @returns {Promise} A promise that eventually resolves with an array of {@link Message} instances.
+   *
+   * @see Client#getMessages
+   * @see PromiseProvider
+   */
+  getMessages(options) {
+    options = options || {};
+    options.ids = this.messageIds;
+
+    return this._jmap.getMessages(options);
+  }
+
+  /**
+   * Updates the isFlagged field of all {@link Message}s of this {@link Thread}.
+   *
+   * @param isFlagged {Boolean} The isFlagged field of the thread.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.setMessages}.
+   *
+   * @see Client#setMessages
+   */
+  setIsFlagged(isFlagged) {
+    return this._flagAllMessages('isFlagged', isFlagged);
+  }
+
+  /**
+   * Updates the isUnread field of this {@link Message}.
+   *
+   * @param isUnread {Boolean} The isUnread field of the thread.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.setMessages}.
+   *
+   * @see Client#setMessages
+   */
+  setIsUnread(isUnread) {
+    return this._flagAllMessages('isUnread', isUnread);
+  }
+
+  /**
+   * Moves this {@link Thread} to a different set of mailboxes.
+   *
+   * @param mailboxIds {String[]} The identifiers of the target mailboxes for the thread.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.setMessages}.
+   *
+   * @see Client#setMessages
+   */
+  move(mailboxIds) {
+    return this._updateAllMessages({ mailboxIds });
+  }
+
+  /**
+   * Moves this {@link Thread} to the mailbox holding the given `role`.<br />
+   * This will first do a JMAP request to find the mailbox with the given role, then a {@link Thread#move} to move the message.
+   *
+   * @param role {MailboxRole|String} The desired mailbox role.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Thread#move}.
+   *
+   * @see MailboxRole
+   * @see Client#getMailboxWithRole
+   */
+  moveToMailboxWithRole(role) {
+    return this._jmap.getMailboxWithRole(role).then(mailbox => this.move([mailbox.id]));
+  }
+
+  /**
+   * Destroy this {@link Thread} on the server.<br />
+   * This will internally destory all messages contained in this thread.
+   *
+   * @return {Promise} A {@link Promise}, as per {@link Client.destroyMessages}.
+   *
+   * @see Client#destroyMessages
+   */
+  destroy() {
+    return this._jmap.destroyMessages(this.messageIds);
+  }
+
+  _updateAllMessages(updates) {
+    let options = {};
+
+    this.messageIds.forEach(id => {
+      options[id] = updates;
+    });
+
+    return this._jmap.setMessages({ update: options });
+  }
+
+  _flagAllMessages(flag, state) {
+    Utils.assertRequiredParameterHasType(state, 'state', 'boolean');
+
+    return this._updateAllMessages({ [flag]: state });
+  }
+
+  /**
+   * Creates a _Thread_ from its JSON representation.
+   *
+   * @param jmap {Client} The {@link Client} instance passed to the _Thread_ constructor.
+   * @param object {Object} The JSON representation of the _Thread_, as a Javascript object.
+   * @param object.id {String} The identifier of the _Thread_.
+   *
+   * @return {Thread}
+   */
+  static fromJSONObject(jmap, object) {
+    Utils.assertRequiredParameterIsPresent(object, 'object');
+
+    return new Thread(jmap, object.id, object);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_VacationResponse.js.html b/doc/api/models_VacationResponse.js.html new file mode 100644 index 0000000..0699ea8 --- /dev/null +++ b/doc/api/models_VacationResponse.js.html @@ -0,0 +1,127 @@ + + + + + JSDoc: Source: models/VacationResponse.js + + + + + + + + + + +
+ +

Source: models/VacationResponse.js

+ + + + + + +
+
+
'use strict';
+
+import Model from './Model.js';
+import Utils from '../utils/Utils.js';
+import JSONBuilder from '../utils/JSONBuilder.js';
+
+class VacationResponse extends Model {
+  /**
+   * This class represents a JMAP [VacationResponse]{@link http://jmap.io/spec.html#vacation-response}.<br />
+   * The _VacationResponse_ object represents the state of vacation-response related settings for an account.
+   *
+   * @constructor
+   * @extends Model
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _VacationResponse_.
+   * @param [opts] {Object} The optional properties of this _VacationResponse_.
+   * @param [opts.isEnabled=false] {Boolean} Is the vacation response enabled?
+   * @param [opts.isActivated=false] {Boolean} Is the vacation response activated?
+   * @param [opts.fromDate=null] {Date} The date/time after which messages that arrive should receive the user’s vacation response, in UTC.
+   * @param [opts.toDate=null] {Date} The date/time after which messages that arrive should no longer receive the user’s vacation response, in UTC.
+   * @param [opts.subject=null] {String} The subject that will be used by the mail sent in response to messages when the vacation response is enabled.
+   * @param [opts.textBody=null] {Number} The plain text part of the message to send in response to messages when the vacation response is enabled.
+   * @param [opts.htmlBody=null] {String} The HTML part of the message to send in response to messages when the vacation response is enabled.
+   *
+   * @see Model
+   */
+  constructor(jmap, opts) {
+    super(jmap);
+
+    opts = opts || {};
+
+    this.id = VacationResponse.ID;
+    this.isEnabled = opts.isEnabled || false;
+    this.isActivated = opts.isActivated || false;
+    this.fromDate = opts.fromDate ? new Date(opts.fromDate) : null;
+    this.toDate = opts.toDate ? new Date(opts.toDate) : null;
+    this.subject = opts.subject || null;
+    this.textBody = opts.textBody || null;
+    this.htmlBody = opts.htmlBody || null;
+  }
+
+  /**
+   * Creates a JSON representation from this {@link VacationResponse}.
+   *
+   * @return JSON object with only owned properties and non-null default values.
+   */
+  toJSONObject() {
+    return new JSONBuilder()
+      .append('id', this.id)
+      .append('isEnabled', this.isEnabled)
+      .appendDateIfDefined('fromDate', this.fromDate)
+      .appendDateIfDefined('toDate', this.toDate)
+      .appendIfDefined('subject', this.subject)
+      .appendIfDefined('textBody', this.textBody)
+      .appendIfDefined('htmlBody', this.htmlBody)
+      .build();
+  }
+
+  /**
+   * Creates an _VacationResponse_ from its JSON representation.
+   *
+   * @param jmap {Client} The {@link Client} instance that created this _VacationResponse_.
+   * @param object {Object} The JSON representation of the _VacationResponse_, as a Javascript object.
+   *
+   * @return {VacationResponse}
+   */
+  static fromJSONObject(jmap, object) {
+    Utils.assertRequiredParameterIsPresent(object, 'object');
+
+    return new VacationResponse(jmap, object);
+  }
+}
+
+VacationResponse.ID = 'singleton'; // http://jmap.io/spec.html#vacation-response
+
+export default VacationResponse;
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/models_filterRules_AbstractConditionAction.js.html b/doc/api/models_filterRules_AbstractConditionAction.js.html new file mode 100644 index 0000000..25900e2 --- /dev/null +++ b/doc/api/models_filterRules_AbstractConditionAction.js.html @@ -0,0 +1,106 @@ + + + + + JSDoc: Source: models/filterRules/AbstractConditionAction.js + + + + + + + + + + +
+ +

Source: models/filterRules/AbstractConditionAction.js

+ + + + + + +
+
+
export default class AbstractConditionAction {
+  constructor(filterRule) {
+    this.filterRule = filterRule;
+    this._init();
+  }
+
+  /**
+   * Do not override
+   * @returns {*}
+   */
+  get when() {
+    return this.filterRule.when;
+  }
+
+  /**
+   * Do not override
+   * @returns {*}
+   */
+  get then() {
+    return this.filterRule.then;
+  }
+
+  /**
+   * Do not override
+   * @returns {*|JSON|{id, name, condition, action}}
+   */
+  toJSONObject() {
+    return this.filterRule.toJSONObject();
+  }
+
+  /**
+   * Initialises the object. Called by the constructor
+   * @private
+   */
+  _init() {
+    throw new Error('_init not implemented in child class');
+  }
+
+  /**
+   * Creates a JSON representation of the model
+   * @private
+   */
+  _toJSONObject() {
+    throw new Error('_toJSONObject not implemented in child class');
+  }
+
+  /**
+   * Validates the object is correct with respect to JMap specification
+   * Will be called by FilterRule#toJSONObject
+   * @private
+   */
+  _validate() {
+    throw new Error('_validate not implemented in child class');
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/module-API.html b/doc/api/module-API.html new file mode 100644 index 0000000..a48afac --- /dev/null +++ b/doc/api/module-API.html @@ -0,0 +1,887 @@ + + + + + JSDoc: Module: API + + + + + + + + + + +
+ +

Module: API

+ + + + + + +
+ +
+ + + + + +
+ +
+
+ + +

The API module is the entry point of the library.
+It exports a single Object that is exposed as, either:

+
    +
  • A global jmap variable when jmap-client included in a web page through a script tag
  • +
  • A NodeJS module when jmap-client is require'd in a NodeJS application
  • +
+

When extending the library with new models, utility classes, etc. don't forget to update this module +so that your new code gets exposed in the public API.
+
+The exported object has the following properties:

+ + + + + + + + + + + + + + + + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
Client + + +Client + + + +

The Client class

Utils + + +Utils + + + +

The Utils class

JSONBuilder + + +JSONBuilder + + + +

The JSONBuilder class helping to serialize model to json

PromiseProvider + + +PromiseProvider + + + +

The PromiseProvider class

ES6PromiseProvider + + +ES6PromiseProvider + + + +

The ES6PromiseProvider class

QPromiseProvider + + +QPromiseProvider + + + +

The QPromiseProvider class

Transport + + +Transport + + + +

The Transport class

JQueryTransport + + +JQueryTransport + + + +

The JQueryTransport class

RequestTransport + + +RequestTransport + + + +

The RequestTransport class

Model + + +Model + + + +

The Model class

Account + + +Account + + + +

The Account class

EMailer + + +EMailer + + + +

The EMailer class

Mailbox + + +Mailbox + + + +

The Mailbox class

MessageList + + +MessageList + + + +

The MessageList class

Message + + +Message + + + +

The Message class

OutboundMessage + + +OutboundMessage + + + +

The OutboundMessage class

CreateMessageAck + + +CreateMessageAck + + + +

The CreateMessageAck class

Thread + + +Thread + + + +

The Thread class

MailboxRole + + +MailboxRole + + + +

The MailboxRole class

SetResponse + + +SetResponse + + + +

The SetResponse class

AuthAccess + + +AuthAccess + + + +

The AuthAccess class

AuthContinuation + + +AuthContinuation + + + +

The AuthContinuation class

Constants + + +Constants + + + +

The Constants object

Attachment + + +Attachment + + + +

The Attachment class

Capabilities + + +Capabilities + + + +

The Capabilities class

MailCapabilities + + +MailCapabilities + + + +

The MailCapabilities class

ServerCapabilities + + +ServerCapabilities + + + +

The ServerCapabilities class

VacationResponse + + +VacationResponse + + + +

The VacationResponse class

TransportError + + +TransportError + + + +

The TransportError class

JmapError + + +JmapError + + + +

The JmapError class

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/module-Constants.html b/doc/api/module-Constants.html new file mode 100644 index 0000000..bf5c1d7 --- /dev/null +++ b/doc/api/module-Constants.html @@ -0,0 +1,211 @@ + + + + + JSDoc: Module: Constants + + + + + + + + + + +
+ +

Module: Constants

+ + + + + + +
+ +
+ + + + + +
+ +
+
+ + +

The Constants module exports a single object that is a collection of useful constants.

+ + + + + + + + + + + + + + + + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
VERSION + + +String + + + +

The version of this library

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + +
+ + + + + + + \ No newline at end of file diff --git a/doc/api/promises_ES6PromiseProvider.js.html b/doc/api/promises_ES6PromiseProvider.js.html new file mode 100644 index 0000000..dc9f38c --- /dev/null +++ b/doc/api/promises_ES6PromiseProvider.js.html @@ -0,0 +1,68 @@ + + + + + JSDoc: Source: promises/ES6PromiseProvider.js + + + + + + + + + + +
+ +

Source: promises/ES6PromiseProvider.js

+ + + + + + +
+
+
'use strict';
+
+import PromiseProvider from './PromiseProvider.js';
+
+/**
+ * A {@link PromiseProvider} implementation creating native ES6 Promises.<br />
+ * This class supposes that the `Promise` class is available.
+ *
+ * @class ES6PromiseProvider
+ *
+ * @see PromiseProvider
+ */
+export default class ES6PromiseProvider extends PromiseProvider {
+  newPromise(resolver) {
+    return new Promise(resolver);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/promises_PromiseProvider.js.html b/doc/api/promises_PromiseProvider.js.html new file mode 100644 index 0000000..dfdacfd --- /dev/null +++ b/doc/api/promises_PromiseProvider.js.html @@ -0,0 +1,86 @@ + + + + + JSDoc: Source: promises/PromiseProvider.js + + + + + + + + + + +
+ +

Source: promises/PromiseProvider.js

+ + + + + + +
+
+
'use strict';
+
+/**
+ * The {@link PromiseProvider} class is the base class for providers of {@link Promise} instances.<br />
+ * A concrete implementation is required to implement {@link PromiseProvider#newPromise} so that this method
+ * returns a {@link Promise} that will be used by the library to do JMAP requests and other asynchronous things.<br />
+ * <br />
+ * This level of abstraction allows users of the library to plug in their own implementation in order to use their
+ * favorite {@link Promise} library. Implementations for [Q]{@link https://github.com/kriskowal/q}
+ * and native [ES6 Promises]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise} are provided.
+ *
+ * @abstract
+ * @class PromiseProvider
+ *
+ * @see ES6PromiseProvider
+ * @see QPromiseProvider
+ */
+export default class PromiseProvider {
+  /**
+   * This method must be implemented by concrete {@link PromiseProvider} implementations in such a way that:
+   * * A {@link Promise} is created from the `resolver` argument and is returned.
+   * * The {@link Promise} will be fulfilled when the `resolve` function of the resolver is called.
+   * * The {@link Promise} will be rejected when the `reject` function of the resolver is called.
+   *
+   * @abstract
+   *
+   * @param resolver {Function} A {@link Function} with two arguments `resolve` and `reject`, both functions.
+   *   The first argument fulfills the promise, the second argument rejects it.
+   *
+   * @return {Promise}
+   */
+  newPromise(resolver) {
+    throw new Error('PromiseProvider is an abstract class. Please use a concrete implementation.');
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/promises_QPromiseProvider.js.html b/doc/api/promises_QPromiseProvider.js.html new file mode 100644 index 0000000..0457891 --- /dev/null +++ b/doc/api/promises_QPromiseProvider.js.html @@ -0,0 +1,68 @@ + + + + + JSDoc: Source: promises/QPromiseProvider.js + + + + + + + + + + +
+ +

Source: promises/QPromiseProvider.js

+ + + + + + +
+
+
'use strict';
+
+import PromiseProvider from './PromiseProvider.js';
+
+/**
+ * A {@link PromiseProvider} implementation creating [Q]{@link https://github.com/kriskowal/q} promises.<br />
+ * This class requires `Q` to be installed as dependency.
+ *
+ * @class QPromiseProvider
+ *
+ * @see PromiseProvider
+ */
+export default class QPromiseProvider extends PromiseProvider {
+  newPromise(resolver) {
+    return require('q').Promise(resolver);
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/scripts/linenumber.js b/doc/api/scripts/linenumber.js new file mode 100644 index 0000000..8d52f7e --- /dev/null +++ b/doc/api/scripts/linenumber.js @@ -0,0 +1,25 @@ +/*global document */ +(function() { + var source = document.getElementsByClassName('prettyprint source linenums'); + var i = 0; + var lineNumber = 0; + var lineId; + var lines; + var totalLines; + var anchorHash; + + if (source && source[0]) { + anchorHash = document.location.hash.substring(1); + lines = source[0].getElementsByTagName('li'); + totalLines = lines.length; + + for (; i < totalLines; i++) { + lineNumber++; + lineId = 'line' + lineNumber; + lines[i].id = lineId; + if (lineId === anchorHash) { + lines[i].className += ' selected'; + } + } + } +})(); diff --git a/doc/api/scripts/prettify/Apache-License-2.0.txt b/doc/api/scripts/prettify/Apache-License-2.0.txt new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/doc/api/scripts/prettify/Apache-License-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/doc/api/scripts/prettify/lang-css.js b/doc/api/scripts/prettify/lang-css.js new file mode 100644 index 0000000..041e1f5 --- /dev/null +++ b/doc/api/scripts/prettify/lang-css.js @@ -0,0 +1,2 @@ +PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", +/^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/doc/api/scripts/prettify/prettify.js b/doc/api/scripts/prettify/prettify.js new file mode 100644 index 0000000..eef5ad7 --- /dev/null +++ b/doc/api/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p p:first-child, +.props td.description > p:first-child +{ + margin-top: 0; + padding-top: 0; +} + +.params td.description > p:last-child, +.props td.description > p:last-child +{ + margin-bottom: 0; + padding-bottom: 0; +} + +.disabled { + color: #454545; +} diff --git a/doc/api/styles/prettify-jsdoc.css b/doc/api/styles/prettify-jsdoc.css new file mode 100644 index 0000000..5a2526e --- /dev/null +++ b/doc/api/styles/prettify-jsdoc.css @@ -0,0 +1,111 @@ +/* JSDoc prettify.js theme */ + +/* plain text */ +.pln { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* string content */ +.str { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a keyword */ +.kwd { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a comment */ +.com { + font-weight: normal; + font-style: italic; +} + +/* a type name */ +.typ { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* a literal value */ +.lit { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* punctuation */ +.pun { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* lisp open bracket */ +.opn { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* lisp close bracket */ +.clo { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a markup tag name */ +.tag { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a markup attribute name */ +.atn { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a markup attribute value */ +.atv { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a declaration */ +.dec { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a variable name */ +.var { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* a function name */ +.fun { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* Specify class=linenums on a pre to get line numbering */ +ol.linenums { + margin-top: 0; + margin-bottom: 0; +} diff --git a/doc/api/styles/prettify-tomorrow.css b/doc/api/styles/prettify-tomorrow.css new file mode 100644 index 0000000..b6f92a7 --- /dev/null +++ b/doc/api/styles/prettify-tomorrow.css @@ -0,0 +1,132 @@ +/* Tomorrow Theme */ +/* Original theme - https://github.com/chriskempson/tomorrow-theme */ +/* Pretty printing styles. Used with prettify.js. */ +/* SPAN elements with the classes below are added by prettyprint. */ +/* plain text */ +.pln { + color: #4d4d4c; } + +@media screen { + /* string content */ + .str { + color: #718c00; } + + /* a keyword */ + .kwd { + color: #8959a8; } + + /* a comment */ + .com { + color: #8e908c; } + + /* a type name */ + .typ { + color: #4271ae; } + + /* a literal value */ + .lit { + color: #f5871f; } + + /* punctuation */ + .pun { + color: #4d4d4c; } + + /* lisp open bracket */ + .opn { + color: #4d4d4c; } + + /* lisp close bracket */ + .clo { + color: #4d4d4c; } + + /* a markup tag name */ + .tag { + color: #c82829; } + + /* a markup attribute name */ + .atn { + color: #f5871f; } + + /* a markup attribute value */ + .atv { + color: #3e999f; } + + /* a declaration */ + .dec { + color: #f5871f; } + + /* a variable name */ + .var { + color: #c82829; } + + /* a function name */ + .fun { + color: #4271ae; } } +/* Use higher contrast and text-weight for printable form. */ +@media print, projection { + .str { + color: #060; } + + .kwd { + color: #006; + font-weight: bold; } + + .com { + color: #600; + font-style: italic; } + + .typ { + color: #404; + font-weight: bold; } + + .lit { + color: #044; } + + .pun, .opn, .clo { + color: #440; } + + .tag { + color: #006; + font-weight: bold; } + + .atn { + color: #404; } + + .atv { + color: #060; } } +/* Style */ +/* +pre.prettyprint { + background: white; + font-family: Consolas, Monaco, 'Andale Mono', monospace; + font-size: 12px; + line-height: 1.5; + border: 1px solid #ccc; + padding: 10px; } +*/ + +/* Specify class=linenums on a pre to get line numbering */ +ol.linenums { + margin-top: 0; + margin-bottom: 0; } + +/* IE indents via margin-left */ +li.L0, +li.L1, +li.L2, +li.L3, +li.L4, +li.L5, +li.L6, +li.L7, +li.L8, +li.L9 { + /* */ } + +/* Alternate shading for lines */ +li.L1, +li.L3, +li.L5, +li.L7, +li.L9 { + /* */ } diff --git a/doc/api/transport_JQueryTransport.js.html b/doc/api/transport_JQueryTransport.js.html new file mode 100644 index 0000000..29a6987 --- /dev/null +++ b/doc/api/transport_JQueryTransport.js.html @@ -0,0 +1,91 @@ + + + + + JSDoc: Source: transport/JQueryTransport.js + + + + + + + + + + +
+ +

Source: transport/JQueryTransport.js

+ + + + + + +
+
+
'use strict';
+
+/* global jQuery: false */
+
+import Transport from './Transport.js';
+import TransportError from '../errors/TransportError';
+
+export default class JQueryTransport extends Transport {
+  /**
+   * A {@link Transport} implementation for [jQuery]{@link https://jquery.com/}.<br />
+   * This class supposes that the `jQuery` global object is available.
+   *
+   * @constructor
+   *
+   * @param [promiseProvider=null] {PromiseProvider} A {@link PromiseProvider} implementation.
+   *
+   * @see Transport
+   */
+  constructor(promiseProvider) {
+    super();
+
+    this.promiseProvider = promiseProvider;
+  }
+
+  post(url, headers, data, raw) {
+    return this.promiseProvider.newPromise(function(resolve, reject) {
+      jQuery.ajax({
+        url: url,
+        method: 'POST',
+        headers: headers,
+        data: raw ? data : JSON.stringify(data),
+        dataType: raw ? undefined : 'json',
+        processData: false,
+        jsonp: false
+      })
+        .done(resolve)
+        .fail((xhr, statusText, err) => reject(new TransportError(err, xhr.status, xhr.responseText)));
+    });
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/transport_RequestTransport.js.html b/doc/api/transport_RequestTransport.js.html new file mode 100644 index 0000000..e6ca400 --- /dev/null +++ b/doc/api/transport_RequestTransport.js.html @@ -0,0 +1,92 @@ + + + + + JSDoc: Source: transport/RequestTransport.js + + + + + + + + + + +
+ +

Source: transport/RequestTransport.js

+ + + + + + +
+
+
'use strict';
+
+import Transport from './Transport';
+import TransportError from '../errors/TransportError';
+import { SUCCESS_RESPONSE_CODES } from '../utils/Constants';
+
+export default class RequestTransport extends Transport {
+  /**
+   * A {@link Transport} implementation for [Request]{@link https://github.com/request/request}.<br />
+   * This class requires `request` to be installed as dependency.
+   *
+   * @constructor
+   *
+   * @param [promiseProvider=null] {PromiseProvider} A {@link PromiseProvider} implementation.
+   *
+   * @see Transport
+   */
+  constructor(promiseProvider) {
+    super();
+
+    this.promiseProvider = promiseProvider;
+  }
+
+  post(url, headers, data, raw) {
+    return this.promiseProvider.newPromise(function(resolve, reject) {
+      require('request')({
+        url: url,
+        headers: headers,
+        method: 'POST',
+        body: data,
+        json: !raw
+      }, function(err, res, body) {
+        if (err || SUCCESS_RESPONSE_CODES.indexOf(res.statusCode) < 0) {
+          return reject(new TransportError(err, res && res.statusCode, body));
+        }
+
+        resolve(body);
+      });
+    });
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/transport_Transport.js.html b/doc/api/transport_Transport.js.html new file mode 100644 index 0000000..601f24e --- /dev/null +++ b/doc/api/transport_Transport.js.html @@ -0,0 +1,95 @@ + + + + + JSDoc: Source: transport/Transport.js + + + + + + + + + + +
+ +

Source: transport/Transport.js

+ + + + + + +
+
+
'use strict';
+
+/**
+ * The {@link Transport} class is the base class for providers of a HTTP transport layer.<br />
+ * A concrete implementation is required to implement {@link Transport#post} so that this method returns a
+ * {@link Promise} that will be resolved or rejected depending on the result of the underlying HTTP request<br />
+ * To create {@link Promise} instances, a {@link Transport} implementation should use a {@link PromiseProvider}.
+ * {@link Client} instances will automatically provide transports with the configured {@link PromiseProvider} as the
+ * `promiseProvider` property.
+ * <br />
+ * This level of abstraction allows users of the library to plug in their own implementation in order to use their
+ * favorite HTTP transport library. Implementations for [Request]{@link https://github.com/request/request}
+ * and [jQuery]{@link https://jquery.com/} are provided.
+ *
+ * @abstract
+ * @class Transport
+ *
+ * @see JQueryTransport
+ * @see RequestTransport
+ * @see PromiseProvider
+ */
+export default class Transport {
+  /**
+   * This method must be implemented by concrete {@link Transport} implementations in such a way that:
+   * * A HTTP POST request is made on `url` with the given `headers` and `data` (i.e.: payload)
+   * * A {@link Promise} is returned (`this.promiseProvider` will be available to create Promise instances)
+   * * The {@link Promise} is fulfilled when the HTTP request returns 200 (http://jmap.io/spec.html#jmap-over-https)
+   * * The {@link Promise} is rejected if the HTTP request fails, or if the return status code is not 200
+   * * When the {@link Promise} is fulfilled, the raw JMAP response is returned
+   *
+   * @abstract
+   *
+   * @param url {String} The URL to POST to
+   * @param headers {Object} A hash of header names to header values that must be transmitted as part of the request
+   * @param data {*} The request payload, as a Javascript object. It's the responsibility of the {@link Transport} implementation
+   *   to serialize the data as a JSON {@link String} whenever required.
+   * @param raw {Boolean} Whether the requests sends and expects raw (plain text) data instead of the default JSON.
+   *
+   * @return {Promise}
+   */
+  post(url, headers, data, raw) {
+    throw new Error('Transport is an abstract class. Please use a concrete implementation.');
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/utils_Constants.js.html b/doc/api/utils_Constants.js.html new file mode 100644 index 0000000..e36f7e4 --- /dev/null +++ b/doc/api/utils_Constants.js.html @@ -0,0 +1,68 @@ + + + + + JSDoc: Source: utils/Constants.js + + + + + + + + + + +
+ +

Source: utils/Constants.js

+ + + + + + +
+
+
'use strict';
+
+/**
+ * The _Constants_ module exports a single object that is a collection of useful constants.
+ *
+ * @property VERSION {String} The version of this library
+ *
+ * @module Constants
+ */
+export default {
+  VERSION: '__VERSION__',
+  CLIENT_NAME: 'jmap-client (https://github.com/linagora/jmap-client)',
+  SUCCESS_RESPONSE_CODES: [200, 201],
+  ERROR: 'error',
+  CORE_CAPABILITIES_URI: 'http://jmap.io/spec-core.html',
+  MAIL_CAPABILITIES_URI: 'http://jmap.io/spec-mail.html'
+};
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/utils_JSONBuilder.js.html b/doc/api/utils_JSONBuilder.js.html new file mode 100644 index 0000000..61cb19c --- /dev/null +++ b/doc/api/utils_JSONBuilder.js.html @@ -0,0 +1,179 @@ + + + + + JSDoc: Source: utils/JSONBuilder.js + + + + + + + + + + +
+ +

Source: utils/JSONBuilder.js

+ + + + + + +
+
+
'use strict';
+
+import Utils from '../utils/Utils.js';
+
+export default class JSONBuilder {
+  /**
+   * This class helps to create JSON representation from a model.
+   * Usage:
+   *
+   *       return new JSONBuilder()
+   *         .appendIfDefined('inReplyToMessageId', this.inReplyToMessageId)
+   *         .appendIfDefined('isUnread', this.isUnread)
+   *         .appendIfDefined('isFlagged', this.isFlagged)
+   *         .build();
+   *
+   * @constructor
+   **/
+  constructor() {
+    this.result = {};
+  }
+
+  /**
+   * Will append the _value_ to the building object, using the _name_ as key.
+   *
+   * @param name {String} The name to use as key.
+   * @param value {*} The value to append.
+   *
+   * @return this builder
+   **/
+  append(name, value) {
+    Utils.assertRequiredParameterIsPresent(name, 'name');
+    Utils.assertRequiredParameterIsPresent(value, 'value');
+
+    this.result[name] = value;
+
+    return this;
+  }
+
+  /**
+   * If defined, it will append the _value_ to the building object, using the _name_ as key.
+   *
+   * @param name {String} The name to use as key.
+   * @param [value] {*} The value to append.
+   *
+   * @return this builder
+   **/
+  appendIfDefined(name, value) {
+    if (Utils.isDefined(value)) {
+      this.append(name, value);
+    }
+
+    return this;
+  }
+
+  /**
+   * If defined, it will append _date_ to the building object as an ISO Date String, using _name_ as the key.
+   *
+   * @param name {String} The name to use as key.
+   * @param [date] {Date} The `Date` to append.
+   *
+   * @return This {@link JSONBuilder} instance
+   *
+   * @see http://jmap.io/spec.html#the-date-datatypes
+   **/
+  appendDateIfDefined(name, date) {
+    if (Utils.isDefined(date)) {
+      Utils.assertRequiredParameterHasType(date, 'date', Date);
+
+      this.append(name, date.toISOString().replace(/.\d+Z/, 'Z')); // Milliseconds should not be there, as per https://tools.ietf.org/html/rfc3339
+    }
+
+    return this;
+  }
+
+  /**
+   * If defined and not empty, it will append the _value_ array to the building object, using the _name_ as key.
+   *
+   * @param name {String} The name to use as key.
+   * @param [value] {Array} The value to append.
+   *
+   * @return this builder
+   **/
+  appendIfNotEmpty(name, value) {
+    if (value) {
+      Utils.assertRequiredParameterIsArrayWithMinimumLength(value, name);
+      if (value.length > 0) {
+        this.append(name, value.map(item => item.toJSONObject ? item.toJSONObject() : item));
+      }
+    }
+
+    return this;
+  }
+
+  /**
+   * Will append the _value_ object to the building object by recursively calling toJSONObject()
+   * on each child if an object.
+   *
+   * @param name {String} The name to use as key.
+   * @param value {Array} The `Object` to append
+   */
+  appendObject(name, value) {
+    let key, obj = {};
+
+    Utils.assertRequiredParameterIsObject(value, 'value');
+
+    for (key in value) {
+      if (value.hasOwnProperty(key)) {
+        if (typeof value[key] === 'object' && value[key].toJSONObject) {
+          obj[key] = value[key].toJSONObject();
+        } else {
+          obj[key] = value[key];
+        }
+      }
+    }
+
+    this.append(name, obj);
+
+    return this;
+  }
+
+  /**
+   * @return an object with all appended values
+   **/
+  build() {
+    return this.result;
+  }
+
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + + diff --git a/doc/api/utils_Utils.js.html b/doc/api/utils_Utils.js.html new file mode 100644 index 0000000..46fe370 --- /dev/null +++ b/doc/api/utils_Utils.js.html @@ -0,0 +1,346 @@ + + + + + JSDoc: Source: utils/Utils.js + + + + + + + + + + +
+ +

Source: utils/Utils.js

+ + + + + + +
+
+
'use strict';
+
+import { ERROR } from './Constants';
+
+export default class Utils {
+  /**
+   * This class contains some useful utility methods.<br />
+   * The Utils class cannot be instantiated (its constructor will throw if called), all its methods are static.
+   *
+   * @constructor
+   */
+  constructor() {
+    throw new Error('The Utils class cannot be instantiated.');
+  }
+
+  /**
+   * Check is the `parameter` is not undefined and not null.
+   *
+   * @param parameter {*} The parameter to check.
+   *
+   * @return {Boolean} True if `parameter` is not undefined and not null.
+   */
+  static isDefined(parameter) {
+    return typeof parameter !== 'undefined' && parameter !== null;
+  }
+
+  /**
+   * Asserts that the given `parameter` is present (read: truthy).<br />
+   * This method is intended to be called when you need to validate input parameters of functions.
+   *
+   * @param parameter {*} The parameter to validate.
+   * @param name {String} The name of the parameter, as given to the calling function.
+   *   This is used to format the error message contained by the thrown {@link Error}.
+   * @param message {String} Optionnal alternative message to display when error
+   *
+   * @return {*} The validated parameter, as-is.
+   *
+   * @throws {Error} If the parameter is not defined.
+   */
+  static assertRequiredParameterIsPresent(parameter, name, message = null) {
+    message = message || `The ${name} parameter is required`;
+    if (!Utils.isDefined(parameter)) {
+      throw new Error(message);
+    }
+
+    return parameter;
+  }
+
+  /**
+   * Asserts that the given `parameter` is present and is an object.<br />
+   * This method is intended to be called when you need to validate input parameters of functions.
+   *
+   * @param parameter {*} The parameter to validate.
+   * @param name {String} The name of the parameter, as given to the calling function.
+   *   This is used to format the error message contained by the thrown {@link Error}.
+   *
+   * @return {*} The validated parameter, as-is.
+   *
+   * @throws {Error} If the parameter is not defined or is not an object.
+   */
+  static assertRequiredParameterIsObject(parameter, name) {
+    Utils.assertRequiredParameterIsPresent(parameter, name);
+
+    if (typeof parameter !== 'object' || Array.isArray(parameter)) {
+      throw new Error('The "' + name + '" parameter is not an object.');
+    }
+
+    return parameter;
+  }
+
+  /**
+   * Asserts that the given `parameter` is present and has the expected type.<br />
+   * This method is intended to be called when you need to validate input parameters of functions.
+   * Examples:
+   *     assertRequiredParameterHasType(5, 'name', 'number') => returns 5
+   *     assertRequiredParameterHasType({}, 'name', CustomClass) => throws an Error
+   *
+   * @param parameter {*} The parameter to validate.
+   * @param name {String} The name of the parameter, as given to the calling function.
+   *   This is used to format the error message contained by the thrown {@link Error}.
+   * @param type {String|Type} The expected type of the parameter.
+   *
+   * @return {*} The validated parameter, as-is.
+   *
+   * @throws {Error} If the parameter is not defined or is not an object.
+   */
+  static assertRequiredParameterHasType(parameter, name, type) {
+    Utils.assertRequiredParameterIsPresent(parameter, name);
+
+    if (typeof type === 'string') {
+      if (typeof parameter !== type) {
+        throw new Error('The "' + name + '" parameter has not the expected type: ' + type);
+      }
+    } else if (!(parameter instanceof type)) {
+      throw new Error('The "' + name + '" parameter has not the expected type: ' + type);
+    }
+
+    return parameter;
+  }
+
+  /**
+   * Asserts that the given `parameter` is an {@link Array} with a minimum length.<br />
+   * This method is intended to be called when you need to validate input parameters of functions.
+   *
+   * @param parameter {*} The parameter to validate.
+   * @param name {String} The name of the parameter, as given to the calling function.
+   *   This is used to format the error message contained by the thrown {@link Error}.
+   * @param [length=0] {Number} The minimum required length of the array.
+   *
+   * @return {*} The validated parameter, as-is.
+   *
+   * @throws {Error} If the parameter is not an array of does not have the minimum length.
+   */
+  static assertRequiredParameterIsArrayWithMinimumLength(parameter, name, length) {
+    if (!Array.isArray(parameter)) {
+      throw new Error('The "' + name + '" parameter must be an Array.');
+    }
+
+    if (length && parameter.length < length) {
+      throw new Error('The "' + name + '" parameter must have at least ' + length + ' element(s).');
+    }
+
+    return parameter;
+  }
+
+  /**
+   * Asserts that the given `data` is a valid JMAP response.<br />
+   * This method is intended to be called by instances of {@link Client}, or by any other object making JMAP requests,
+   * when validation of the response is required.<br />
+   * <br />
+   * The following checks are made by this method:
+   * * `data` is defined and is an array
+   * * `data` has one or more elements, and all elements are arrays
+   * * `data[0][0]` is either
+   *   * the expected response string (computed with the help of the `request` parameter)
+   *   * 'error'
+   *   * an unknown response
+   * * `data[0][1]` exists
+   *
+   * @param request {String} The JMAP request to check the response for. This should be a valid JMAP request name.
+   * @param data {*} The JMAP response to validate.
+   *
+   * @return {*} The data, as-is, if it is detected as a valid JMAP response.
+   *
+   * @throws {Error} If the received data is not a valid JMAP response.
+   */
+  static assertValidJMAPResponse(request, data) {
+    function allArrayElementsAreArray(array) {
+      return array.filter(function(element) {
+        return !Array.isArray(element);
+      }).length === 0;
+    }
+
+    if (!data || !Array.isArray(data)) {
+      throw new Error(`Expected an array as the JMAP response for a "${request}" request.`);
+    }
+
+    if (data.length === 0 || !allArrayElementsAreArray(data)) {
+      throw new Error(`Expected an array of exactly 1 array element as the JMAP response for a "${request}" request.`);
+    }
+
+    let response = data[0][0],
+      expectedResponse = Utils._expectedResponseFor(request);
+
+    if (response !== ERROR && (expectedResponse && response !== expectedResponse)) {
+      throw new Error(`Expected "${expectedResponse}" as the JMAP response for a "${request}" request, but got "${response}".`);
+    }
+
+    if (!data[0][1]) {
+      throw new Error(`The JMAP response for a "${request}" request should return some data.`);
+    }
+
+    return data;
+  }
+
+  /**
+   * Capitalizes the given {@link String}, that is, returns the same string with the first character in uppercase.<br />
+   * If `undefined`, `null`, the _empty string_ or something else that a string is given, the argument is returned as-is.
+   *
+   * @param str {String} The {@link String} to capitalize.
+   *
+   * @return {String} The capitalized {@link String}.
+   */
+  static capitalize(str) {
+    if (!str || typeof str !== 'string') {
+      return str;
+    }
+
+    return str.charAt(0).toUpperCase() + str.substring(1);
+  }
+
+  /**
+   * Fills a URI template by substituting variables by their corresponding values.<br />
+   * This supports Level 1 URI templates *only*, as per [this RFC](https://tools.ietf.org/html/rfc6570#section-1.2).
+   *
+   * @param uri {String} The URI template to fill.
+   * @param parameters {Object} A hash of name/value pairs used for variables substitution.
+   *
+   * @return {String} The filled URI template.
+   */
+  static fillURITemplate(uri, parameters) {
+    Utils.assertRequiredParameterIsPresent(uri, 'uri');
+
+    if (!parameters) {
+      return uri;
+    }
+
+    return uri.replace(/{(.+?)}/g, function(match, variable) {
+      let value = parameters[variable];
+
+      return value ? encodeURIComponent(value) : match;
+    });
+  }
+
+  /**
+   * Appends a query parameter to an existing URL, taking care of existing query parameters.<br />
+   * This method returns `uri` as-is if `key` or `value` is not defined.
+   *
+   * @param uri {String} The URI to modify.
+   * @param key {String} The name of the parameter to append.
+   * @param value {String} The value of the parameter to append.
+   *
+   * @returns {String} The modified URI.
+   */
+  static appendQueryParameter(uri, key, value) {
+    if (!uri || !key || !value) {
+      return uri;
+    }
+
+    return uri + (uri.indexOf('?') > -1 ? '&' : '?') + encodeURIComponent(key) + '=' + encodeURIComponent(value);
+  }
+
+  /**
+   * Returns the value at _index_ in the given  `Array`, or the default value if the array is undefined, null,
+   * if _index_ is negative or there is not enough elements in the array.
+   *
+   * @param array The `Array` to get the value from.
+   * @param index The index of the desired value.
+   * @param defaultValue The default value to return if the element cannot be found in the array.
+   *
+   * @returns {*} The found value or the given default.
+   */
+  static nthElementOrDefault(array, index, defaultValue) {
+    if (Array.isArray(array) && index >= 0 && array.length > index) {
+      return array[index];
+    }
+
+    return defaultValue;
+  }
+
+  /**
+   * Can't make babel pollyfills to work with Karma. This is a hackity hack.
+   * Object.values is part of ES7 standard.
+   * @param object
+   */
+  static objectValues(object) {
+    return Object.keys(object).map(key => object[key]);
+  }
+
+  static objectValuesIncludes(object, value) {
+    return Utils.objectValues(object).indexOf(value) >= 0;
+  }
+
+  static _jsonArrayToModelList(jmap, Model, array, filter) {
+    if (!Array.isArray(array)) {
+      return [];
+    }
+
+    if (filter) {
+      array = array.filter(filter);
+    }
+
+    return array.map(Model.fromJSONObject.bind(null, jmap));
+  }
+
+  static _nullOrNewInstance(value, Model) {
+    return (value && new Model(value)) || null;
+  }
+
+  static _expectedResponseFor(request) {
+    return ({
+      getAccounts: 'accounts',
+      getMailboxes: 'mailboxes',
+      getMessageList: 'messageList',
+      getThreads: 'threads',
+      getMessages: 'messages',
+      setMessages: 'messagesSet',
+      setMailboxes: 'mailboxesSet',
+      getVacationResponse: 'vacationResponse',
+      setVacationResponse: 'vacationResponseSet',
+      getFilter: 'filter',
+      setFilter: 'filterSet'
+    })[request];
+  }
+}
+
+
+
+ + + + +
+ + + +
+ + + + + + +