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G,OAAO,EAAc,OACvB,GACF,GAOC,CACD,IAAK,mBACL,MAAO,WACL,OAAO,KAAK,UAAU,2DAA2D,MAAK,SAAU,GAC9F,OAAO,EAAoB,aAC7B,GACF,KAGK,CACT,CA5uBmB,GA8uBnB,OAAO,QAAU","file":"/npm/splitwise-node@0.3.3/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/splitwise-node@0.3.3/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\n\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar OAuth = require('oauth').OAuth;\nvar Promise = require('promise');\nvar util = require('./util');\nvar objectHasInvalidKeys = util.objectHasInvalidKeys;\n\nvar urlUtil = require('./urlUtil');\nvar encodeAsUrlParam = urlUtil.encodeAsUrlParam;\nvar encodeObjectArray = urlUtil.encodeObjectArray;\n\nvar validExpenseKeys = ['group_id', 'friendship_id', 'dated_after', 'dated_before', 'updated_after', 'updated_before', 'limit', 'offset'];\nvar requiredFriendKeys = ['user_email', 'user_first_name'];\nvar optionalFriendKeys = ['user_last_name'];\n\nvar friendHasValidKeys = objectHasInvalidKeys.bind(null, requiredFriendKeys.concat(optionalFriendKeys));\n\nvar AuthApi = function () {\n  function AuthApi(consumerKey, consumerSecret) {\n    _classCallCheck(this, AuthApi);\n\n    this.__auth = new OAuth('https://secure.splitwise.com/api/v3.0/get_request_token', 'https://secure.splitwise.com/api/v3.0/get_access_token', consumerKey, consumerSecret, '1.0', null, 'HMAC-SHA1');\n  }\n\n  // OAuth methods\n  /**\r\n   * Fetch a request token to be authorized by a user.\r\n   *\r\n   * TokenSecret: {\r\n   *   token: string,\r\n   *   secret: string,\r\n   * }\r\n   *\r\n   * @returns {Promise<Error|TokenSecret>}\r\n   */\n\n  _createClass(AuthApi, [{\n    key: 'getOAuthRequestToken',\n    value: function getOAuthRequestToken() {\n      var _this = this;\n\n      return new Promise(function (fulfill, reject) {\n        _this.__auth.getOAuthRequestToken(function (err, oAuthToken, oAuthTokenSecret, results) {\n          if (err) reject(err);else fulfill({ token: oAuthToken, secret: oAuthTokenSecret });\n        });\n      });\n    }\n  }, {\n    key: 'getUserAuthorisationUrl',\n    value: function getUserAuthorisationUrl(oAuthToken) {\n      return 'https://secure.splitwise.com/authorize?oauth_token=' + oAuthToken;\n    }\n\n    // TODO seem to be able to use the api without needing to exchange the request token for an access token\n\n  }, {\n    key: 'getOAuthAccessToken',\n    value: function getOAuthAccessToken(oAuthToken, oAuthTokenSecret, oAuthVerifier) {\n      var _this2 = this;\n\n      return new Promise(function (fulfill, reject) {\n        _this2.__auth.getOAuthAccessToken(oAuthToken, oAuthTokenSecret, oAuthVerifier, function (err, oAuthAccessToken, oAuthAccessTokenSecret) {\n          if (err) reject(err);else fulfill({ oAuthAccessToken: oAuthAccessToken, oAuthAccessTokenSecret: oAuthAccessTokenSecret });\n        });\n      });\n    }\n  }, {\n    key: 'getSplitwiseApi',\n    value: function getSplitwiseApi(oAuthToken, oAuthSecret) {\n      return new SplitwiseApi(this, oAuthToken, oAuthSecret);\n    }\n  }]);\n\n  return AuthApi;\n}();\n\nvar SplitwiseApi = function () {\n  function SplitwiseApi(authApi, oAuthToken, oAuthTokenSecret) {\n    _classCallCheck(this, SplitwiseApi);\n\n    this.__auth = authApi.__auth;\n    this.oAuthToken = oAuthToken;\n    this.oAuthTokenSecret = oAuthTokenSecret;\n  }\n\n  _createClass(SplitwiseApi, [{\n    key: '__parseResponse',\n    value: function __parseResponse(reject, fulfill, err, data) {\n      if (err) {\n        reject({\n          statusCode: err.statusCode,\n          error: JSON.parse(err.data).error\n        });\n      } else {\n        fulfill(JSON.parse(data));\n      }\n    }\n  }, {\n    key: '__authGet',\n    value: function __authGet(url) {\n      var _this3 = this;\n\n      return new Promise(function (fulfill, reject) {\n        _this3.__auth.get(url, _this3.oAuthToken, _this3.oAuthTokenSecret, _this3.__parseResponse.bind(_this3, reject, fulfill));\n      });\n    }\n  }, {\n    key: '__authPost',\n    value: function __authPost(url, body) {\n      var _this4 = this;\n\n      var contentType = 'application/json';\n      return new Promise(function (fulfill, reject) {\n        _this4.__auth.post(url, _this4.oAuthToken, _this4.oAuthTokenSecret, body, contentType, _this4.__parseResponse.bind(_this4, reject, fulfill));\n      });\n    }\n  }, {\n    key: '__authPut',\n    value: function __authPut(url, body) {\n      var _this5 = this;\n\n      var contentType = 'application/json';\n      return new Promise(function (fulfill, reject) {\n        _this5.__auth.put(url, _this5.oAuthToken, _this5.oAuthTokenSecret, body, contentType, _this5.__parseResponse.bind(_this5, reject, fulfill));\n      });\n    }\n  }, {\n    key: '__authDelete',\n    value: function __authDelete(url) {\n      var _this6 = this;\n\n      return new Promise(function (fulfill, reject) {\n        _this6.__auth.delete(url, _this6.oAuthToken, _this6.oAuthTokenSecret, _this6.__parseResponse.bind(_this6, reject, fulfill));\n      });\n    }\n\n    // Api Methods\n    /**\r\n     * A service health-check\r\n     *\r\n     * @returns {Promise<boolean>}\r\n     */\n\n  }, {\n    key: 'isServiceOk',\n    value: function isServiceOk() {\n      return this.__authGet('https://secure.splitwise.com/api/v3.0/test').then(function () {\n        return true;\n      }).catch(function () {\n        return false;\n      });\n    }\n\n    /**\r\n     * Returns a list of all currencies allowed by the system\r\n     * Currency: { currency_code: 'GBP', unit: '£' }\r\n     *\r\n     * @returns {Promise<Error|Array>}\r\n     */\n\n  }, {\n    key: 'getCurrencies',\n    value: function getCurrencies() {\n      return this.__authGet('https://secure.splitwise.com/api/v3.0/get_currencies').then(function (data) {\n        return data['currencies'];\n      });\n    }\n\n    /**\r\n     * Return an array of all categories\r\n     * Category: {\r\n     *   id: Number\r\n     *   name: String\r\n     *   icon: String // TODO dimensions\r\n     *   icon_types: {\r\n     *    slim: {\r\n     *      small: String,\r\n     *      large: String\r\n     *    }\r\n     *   },\r\n     *   subcategories: Array<Category>\r\n     * }\r\n     *\r\n     * @returns {Promise<Error|Array>}\r\n     */\n\n  }, {\n    key: 'getCategories',\n    value: function getCategories() {\n      return this.__authGet('https://secure.splitwise.com/api/v3.0/get_categories').then(function (data) {\n        return data['categories'];\n      });\n    }\n\n    /**\r\n     * Return a suggested expense for a natural language sentence\r\n     * ExpenseSuggestion: {\r\n     *   expense: Expense,\r\n     *   valid: Boolean,\r\n     *   confidence: Number\r\n     * }\r\n     *\r\n     * @param {String} sentence\r\n     * @param {Number} friendId\r\n     * @param {Boolean} [autosave]\r\n     * @returns {Promise<Error|ExpenseSuggestion>}\r\n     */\n\n  }, {\n    key: 'parseSentence',\n    value: function parseSentence(sentence, friendId, autosave) {\n      var paramString = encodeAsUrlParam({\n        input: sentence,\n        friend_id: friendId,\n        autosave: autosave || undefined\n      });\n\n      return this.__authPost('https://secure.splitwise.com/api/v3.0/parse_sentence?' + paramString, null);\n    }\n\n    // Users\n    /**\r\n     * Returns the current user\r\n     *\r\n     * User: {\r\n     *   id: Number,\r\n     *   first_name: String,\r\n     *   last_name: String,\r\n     *   picture: {\r\n     *     small: String,\r\n     *     medium: String,\r\n     *     large: String\r\n     *   },\r\n     *   email: String,\r\n     *   registration_status: String, // One if “dummy”, “invited”, and “confirmed”.\r\n     *   force_refresh_at: null,\r\n     *   locale: null,\r\n     *   country_code: 'GB',\r\n     *   date_format: 'MM/DD/YYYY',\r\n     *   default_currency: 'GBP',\r\n     *   default_group_id: -1,\r\n     *   notifications_read: '2015-12-24T13:44:37Z',\r\n     *   notifications_count: 0,\r\n     *   notifications: {\r\n     *     added_as_friend: false,\r\n     *     added_to_group: true,\r\n     *     expense_added: false,\r\n     *     expense_updated: false,\r\n     *     bills: true,\r\n     *     payments: true,\r\n     *     monthly_summary: true,\r\n     *     announcements: true\r\n     *   }\r\n     * }\r\n     *\r\n     * @returns {Promise<Error|User>}\r\n     */\n\n  }, {\n    key: 'getCurrentUser',\n    value: function getCurrentUser() {\n      return this.__authGet('https://secure.splitwise.com/api/v3.0/get_current_user').then(function (data) {\n        return data.user;\n      });\n    }\n\n    /**\r\n     * Returns the user with the provided id\r\n     * See getFriend\r\n     *\r\n     * @param {Number} userId\r\n     * @returns {Promise<Error|User>}\r\n     */\n\n  }, {\n    key: 'getUser',\n    value: function getUser(userId) {\n      return this.__authGet('https://secure.splitwise.com/api/v3.0/get_user/' + userId);\n    }\n\n    /**\r\n     * Update user information for the given user. A user can edit anything about himself,\r\n     * and (first_name, last_name, email) for users whom he is acquainted with but haven’t logged in yet.\r\n     *\r\n     * @param {Number} userId\r\n     * @param {Object} user\r\n     * @returns {Promise<Error|user>} - The detailed updated user\r\n     */\n\n  }, {\n    key: 'updateUser',\n    value: function updateUser(userId, user) {\n      var validUserKeys = ['first_name', 'last_name', 'email', 'password', 'locale', 'date_format', 'default_currency', 'default_group_id'];\n      // TODO figure out how to update notification settings\n      var validNotificationSettings = ['notification_settings', 'added_as_friend', 'added_to_group', 'expense_added', 'expense_updated', 'bills', 'payments', 'monthly_summary', 'announcements'];\n\n      var invalidKeysError = objectHasInvalidKeys(validUserKeys, user);\n      if (invalidKeysError) {\n        return Promise.reject(invalidKeysError);\n      }\n\n      var paramString = encodeAsUrlParam(user);\n      return this.__authPut('https://secure.splitwise.com/api/v3.0/update_user/' + userId + '?' + paramString, null).then(function (data) {\n        return data['user'];\n      });\n    }\n\n    // Groups\n    /**\r\n     * Returns list of all groups that the current_user belongs to\r\n     *\r\n     * @returns {Promise<Error|Array>} - Detailed info for all groups that include the authenticated user\r\n     */\n\n  }, {\n    key: 'getGroups',\n    value: function getGroups() {\n      return this.__authGet('https://secure.splitwise.com/api/v3.0/get_groups').then(function (data) {\n        return data['groups'];\n      });\n    }\n\n    /**\r\n     * Get detailed info on one group that current_user belongs to\r\n     *\r\n     * Debt: {\r\n     *   from: Number, // A user id\r\n     *   to: Number, // A user id\r\n     *   amount: String, // eg '24.98'\r\n     *   currency_code: String // See getCurrencies\r\n     * }\r\n     *\r\n     * Group: {\r\n     *   id: 0,\r\n     *   name: 'Non-group expenses',\r\n     *   updated_at: '2015-12-24T14:04:44Z',\r\n     *   members: Array<UserBasic>,\r\n     *   simplify_by_default: false,\r\n     *   original_debts: Array<Debt>\r\n     *   simplified_debts: Array<Debt\r\n     * }\r\n     *\r\n     * @param {Number} groupId\r\n     * @returns {Promise<Error|Array>}\r\n     */\n\n  }, {\n    key: 'getGroup',\n    value: function getGroup(groupId) {\n      return this.__authGet('https://secure.splitwise.com/api/v3.0/get_group/' + groupId).then(function (data) {\n        return data['group'];\n      });\n    }\n\n    /**\r\n     * Create a new group. Adds the current user to the group by default.\r\n     *\r\n     * Successful response: {\r\n     *   id: Number,\r\n     *   name: String,\r\n     *   updated_at: '2015-12-27T12:49:56Z',\r\n     *   members: [Member, Member],\r\n     *   simplify_by_default: Boolean,\r\n     *   original_debts: Array,\r\n     *   simplified_debts: Array,\r\n     *   whiteboard: null,\r\n     *   group_type: String,\r\n     *   invite_link: String\r\n     * }\r\n     *\r\n     * In the event of an error, an 'Errors' object will be returned. Eg:\r\n     * Failure response: {\r\n     *   statusCode: Number,\r\n     *   errors: {\r\n     *     'someParamName': Array<String>\r\n     *   }\r\n     * }\r\n     * Where someParamName represents on of the API parameter's names\r\n     *\r\n     * @param {String} name\r\n     * @param {Array<Object>} members - member:  {first_name, last_name, email } or  { user_id }\r\n     * @param {String} [groupType]\r\n     * @param {String} [countryCode]\r\n     * @returns {Promise<Object|Object>}\r\n     */\n\n  }, {\n    key: 'createGroup',\n    value: function createGroup(name, members, groupType, countryCode) {\n      if (!name || name == '') {\n        return Promise.reject({ statusCode: 400, errors: { name: [\"can't be blank\"] } });\n      }\n      var paramString = encodeAsUrlParam({\n        name: name,\n        group_type: groupType,\n        country_code: countryCode,\n        members: encodeObjectArray('users', members)\n      });\n\n      return this.__authPost('https://secure.splitwise.com/api/v3.0/create_group?' + paramString, null).then(function (data) {\n        if (data.group.errors) {\n          return Promise.reject({ statusCode: 400, errors: data.group.errors });\n        }\n        return data.group;\n      });\n    }\n\n    /**\r\n     * @param {String} groupId\r\n     * @returns {Promise<Error|Boolean>} - success\r\n     */\n\n  }, {\n    key: 'deleteGroup',\n    value: function deleteGroup(groupId) {\n      return this.__authPost('https://secure.splitwise.com/api/v3.0/delete_group/' + groupId).then(function (data) {\n        return data['success'];\n      });\n    }\n\n    /**\r\n     * Add a user to the group\r\n     // TODO according to the docs this can return an error on two different ways, e.g\r\n     * fail1: { statusCode: 404, error: 'Invalid API Request: record not found' }\r\n     * fail2: { errors: [ ??? ] }\r\n     * Need a way to normalise these into a single error format\r\n     *\r\n     * Provide either a userId: number or a user: { first_name, last_name, email }\r\n     * @param {Number} groupId\r\n     * @param {Number|Object} [user|userId]\r\n     * @returns {Promise<Error|User>} - Returns either the user which has been added to the group, or an object with an array of errors, or an object with a single error\r\n     */\n\n  }, {\n    key: 'addUserToGroup',\n    value: function addUserToGroup(groupId, user) {\n      var paramString = undefined;\n      if (typeof user === 'number') {\n        paramString = encodeAsUrlParam({ group_id: groupId, user_id: user });\n      } else {\n        var first_name = user.first_name;\n        var last_name = user.last_name;\n        var email = user.email;\n\n        paramString = encodeAsUrlParam({ group_id: groupId, first_name: first_name, last_name: last_name, email: email });\n      }\n      return this.__authPost('https://secure.splitwise.com/api/v3.0/add_user_to_group?' + paramString, null).then(function (data) {\n        if (!data.success) {\n          return Promise.reject({ errors: data.errors });\n        }\n        return data.user;\n      });\n    }\n\n    /**\r\n     * Remove a user from a group, Only if their balance is 0\r\n     *\r\n     * TODO can return an error in two different ways, need to normalise\r\n     *\r\n     * @param {Number} groupId\r\n     * @param {Number} userId\r\n     * @returns {Promise<Boolean|Error>} - Returns either a boolean to indicate success, or an object with an errors key which contains an array of strings\r\n     */\n\n  }, {\n    key: 'removeUserFromGroup',\n    value: function removeUserFromGroup(groupId, userId) {\n      var paramString = encodeAsUrlParam({ group_id: groupId, user_id: userId });\n      return this.__authPost('https://secure.splitwise.com/api/v3.0/remove_user_from_group?' + paramString, null).then(function (data) {\n        if (!data.success) {\n          return Promise.reject({ errors: data.errors });\n        }\n        return true;\n      });\n    }\n\n    // Expenses\n    /**\r\n     * Return expenses involving the current user, in reverse chronological order\r\n     * ExpensesConfig: {\r\n     *   group_id: Number\r\n     *   friendship_id: Number\r\n     *   dated_after\r\n     *   dated_before\r\n     *   updated_after\r\n     *   updated_before\r\n     *   limit: Number (defaults to 20; set to 0 to fetch all)\r\n     *   offset:Number\r\n     * }\r\n     *\r\n     * // TODO this what the api really returns, the docs aren't up to date\r\n     * Expense: {\r\n     *   id: Number\r\n     *   group_id: Number\r\n     *   friendship_id: Number\r\n     *   expense_bundle_id: Number\r\n     *   description: String\r\n     *   details:String\r\n     *   payment,\r\n     *   repeats: Boolean,\r\n     *   repeat_interval: String // 'never',\r\n     *   cost: String, // '25.0'\r\n     *   date: '2015-12-24T13:31:35Z',\r\n     *   created_at: '2015-12-24T13:32:41Z',\r\n     *   created_by: UserBasic\r\n     *   updated_at: '2015-12-24T13:44:06Z',\r\n     *   updated_by: UserBasic\r\n     *   deleted_at: '2015-12-24T13:44:06Z',\r\n     *   deleted_by: UserBasic,\r\n     *   category: {\r\n     *     id: Number,\r\n     *     name: String\r\n     *   },\r\n     * // The following are not detailed in the api docs\r\n     *  email_reminder: Boolean,\r\n     *  email_reminder_in_advance: Number,\r\n     *  next_repeat: null,\r\n     *  details: null,\r\n     *  comments_count: 2,\r\n     *  payment: false,\r\n     *  creation_method: 'equal',\r\n     *  transaction_method: 'offline',\r\n     *  transaction_confirmed: false,\r\n     *  currency_code: 'GBP',\r\n     *  repayments: [ { from: 3089683, to: 1388992, amount: '25.0' } ],\r\n     *  receipt: { large: null, original: null },\r\n     *  users: [\r\n     *    {\r\n     *      user: UserBasic,\r\n     *      user_id: Number,\r\n     *      paid_share: '0.0',\r\n     *      owed_share: '25.0',\r\n     *     net_balance: '-25.0'\r\n     *    },\r\n     *  ],\r\n     *  comments: [\r\n     *    {\r\n     *      id: Number,\r\n     *      content: 'Pay fast',\r\n     *      comment_type: 'User',\r\n     *      relation_type: 'ExpenseComment',\r\n     *      relation_id: 68735153,\r\n     *      created_at: '2015-12-24T13:43:32Z',\r\n     *      deleted_at: null,\r\n     *      user: [Object]\r\n     *    },\r\n     *  ]\r\n     * }\r\n     *\r\n     * @param {Object} [expensesConfig]\r\n     * @returns {Promise<Error|Array<Expense>>}\r\n     */\n\n  }, {\n    key: 'getExpenses',\n    value: function getExpenses(expensesConfig) {\n      var baseUrl = 'https://secure.splitwise.com/api/v3.0/get_expenses';\n      var requestUrl = baseUrl;\n      if (expensesConfig) {\n        var invalidKeysError = objectHasInvalidKeys(validExpenseKeys, expensesConfig);\n        if (invalidKeysError) {\n          return Promise.reject(invalidKeysError);\n        }\n        requestUrl = baseUrl + '?' + encodeAsUrlParam(expensesConfig);\n      }\n\n      return this.__authGet(requestUrl).then(function (data) {\n        return data['expenses'].filter(function (expense) {\n          return expense['deleted_at'] == null;\n        });\n      });\n    }\n\n    /**\r\n     * Returns expenses which have been deleted involving the user. Api is the same as for getExpenses\r\n     * @param {Object} [expensesConfig]\r\n     * @returns {Promise<Error|Array<Expense>>}\r\n     */\n\n  }, {\n    key: 'getDeletedExpenses',\n    value: function getDeletedExpenses(expensesConfig) {\n      var baseUrl = 'https://secure.splitwise.com/api/v3.0/get_expenses';\n      var requestUrl = baseUrl;\n      if (expensesConfig) {\n        var invalidKeysError = objectHasInvalidKeys(this.validExpenseKeys, expensesConfig);\n        if (invalidKeysError) {\n          return Promise.reject(invalidKeysError);\n        }\n        requestUrl = baseUrl + '?' + encodeAsUrlParam(expensesConfig);\n      }\n      return this.__authGet(requestUrl).then(function (data) {\n        return data['expenses'].filter(function (expense) {\n          return expense['deleted_at'] != null;\n        });\n      });\n    }\n\n    /**\r\n     * Return full details on an expense involving the current user\r\n     * @param {Number} expenseId\r\n     * @returns {Promise<Error|Expense>}\r\n     */\n\n  }, {\n    key: 'getExpense',\n    value: function getExpense(expenseId) {\n      return this.__authGet('https://secure.splitwise.com/api/v3.0/get_expense/' + expenseId).then(function (data) {\n        return data['expense'];\n      });\n    }\n\n    /**\r\n     * Add an expense\r\n     * TODO explain the structure of these errors & params\r\n     * ErrorObj: {\r\n     *   base: [\r\n     *     'The total of everyone\\'s owed shares ($5.00) is different than the total cost ($9.99)',\r\n     *     'The total of everyone\\'s paid shares ($0.00) is different than the total cost ($9.99)',\r\n     *     'You cannot add an expense that does not involve yourself, unless that expense is in a group.'\r\n     *   ],\r\n     *   description: [ 'can\\'t be blank' ]\r\n     * }\r\n     *\r\n     * @param {Object} expense\r\n     * @param {Array<UserShare>} userShares\r\n     * @returns {Promise<ErrorObj|Array<Expense>>} - Returns an array containing the expense which has just been created or an object with an errors key\r\n     */\n\n  }, {\n    key: 'createExpense',\n    value: function createExpense(expense, userShares) {\n      // TODO validate expense keys\n      var requiredExpenseFields = ['payment', 'cost', 'description'];\n      var optionalFields = ['group_id', 'friendship_id', 'details', 'creation_method', // iou, quickadd, payment, or split\n      'date', 'repeat_interval', // never, weekly, fortnightly, monthly, yearly\n      'currency_code', 'category_id'];\n\n      // TODO validate the userShare keys\n      var userShareKeys = ['user_id', 'paid_share', 'owed_share'];\n\n      // TODO validate the total of the userShares\n\n      var paramString = encodeAsUrlParam(Object.assign({}, expense, { users: encodeObjectArray('users', userShares) }));\n      return this.__authPost('https://secure.splitwise.com/api/v3.0/create_expense?' + paramString, expense).then(function (data) {\n        if (data.errors && Object.keys(data.errors).length != 0) {\n          return Promise.reject(data.errors);\n        }\n\n        return data['expenses'];\n      });\n    }\n\n    // TODO create a method which makes it simpler to create an expense between two users\n\n    /**\r\n     * Edit an expense\r\n     * Returns an array containing the expense which has been created\r\n     *\r\n     * @param {Number} expenseId\r\n     * @param {Object} expenseUpdate\r\n     * @returns {Promise<ErrorObj|Array<Expense>>}\r\n     */\n\n  }, {\n    key: 'updateExpense',\n    value: function updateExpense(expenseId, expenseUpdate) {\n      // TODO validate the keys on expenseUpdate\n      var expenseUpdateFields = ['group_id', 'friendship_id', 'expense_bundle_id', // (TODO the docs give no indication of what this is for)\n      'description', 'details', 'payment', 'cost', 'date', 'category_id', 'users' // TODO figure out how nested params work as\n      ];\n\n      var userShareUpdate = ['user_id', 'paid_share', 'owed_share'];\n\n      var paramString = encodeAsUrlParam(expenseUpdate);\n\n      return this.__authPost('https://secure.splitwise.com/api/v3.0/update_expense/' + expenseId + '?' + paramString, null).then(function (data) {\n        if (data.errors && Object.keys(data.errors).length > 0) {\n          return Promise.reject(data.errors);\n        }\n\n        return data['expenses'];\n      });\n    }\n\n    /**\r\n     * Delete an expense\r\n     *\r\n     * @param {Number} expenseId\r\n     * @returns {Promise<ErrorObj|Boolean>}\r\n     */\n\n  }, {\n    key: 'deleteExpense',\n    value: function deleteExpense(expenseId) {\n      return this.__authPost('https://secure.splitwise.com/api/v3.0/delete_expense/' + expenseId).then(function (data) {\n        if (data.errors && Object.keys(data.errors).length > 0) {\n          return Promise.reject(data.errors);\n        }\n\n        return data.success;\n      });\n    }\n\n    // Friends\n\n    /**\r\n     * Returns an array of users\r\n     *\r\n     * User: {\r\n     *   id: Number,\r\n     *   first_name: String,\r\n     *   last_name: [String],\r\n     *   email: String,\r\n     *   registration_status: String, // One if “dummy”, “invited”, and “confirmed”.\r\n     *   picture: {\r\n     *     small: String, // 50px by 50px\r\n     *     medium: String, // 100px by 100px\r\n     *     large: String // 200px by 200px\r\n     *   },\r\n     *   balance: [ currency_code, amount ], // An array with two elements, in element 0 a three character currency code (see getCurrencies) and in element 1 the amount, as a String\r\n     *   groups: Array<Group>,\r\n     *   updated_at: '2015-12-27T22:30:52Z'\r\n     * }\r\n     *\r\n     * @returns {Promise<Error|Array<User>>}\r\n     */\n\n  }, {\n    key: 'getFriends',\n    value: function getFriends() {\n      return this.__authGet('https://secure.splitwise.com/api/v3.0/get_friends').then(function (data) {\n        return data['friends'];\n      });\n    }\n\n    /**\r\n     * Given a user id, returns the “friend” object of the user\r\n     * @returns {Promise<Error|User>}\r\n     */\n\n  }, {\n    key: 'getFriend',\n    value: function getFriend(friendId) {\n      return this.__authGet('http://secure.splitwise.com/api/v3.0/get_friend/' + friendId).then(function (data) {\n        return data['friend'];\n      });\n    }\n\n    /**\r\n     * Makes the current user a friend of a user specified with the url parameters\r\n     * user_email, user_first_name, and, optionally, user_last_name.\r\n     *\r\n     * @param {Object} friend\r\n     * @returns {Promise<Error|User>}\r\n     */\n\n  }, {\n    key: 'createFriend',\n    value: function createFriend(friend) {\n      var keyValidationError = friendHasValidKeys(friend);\n      if (keyValidationError) {\n        return Promise.reject(keyValidationError);\n      }\n      var urlParams = encodeAsUrlParam(friend);\n      return this.__authPost('https://secure.splitwise.com/api/v3.0/create_friend?' + urlParams, friend).then(function (data) {\n        return data['friends'];\n      });\n    }\n\n    /**\r\n     * Make the current user a friend of the specified users. Specify a user with the parameters\r\n     * user_email, user_first_name, and, optionally, user_last_name\r\n     *\r\n     * @param {Array<Object>} friends\r\n     * @returns {Promise<Error|Array<User>>}\r\n     */\n\n  }, {\n    key: 'createFriends',\n    value: function createFriends(friends) {\n      friends.forEach(function (friend) {\n        var keyValidationError = friendHasValidKeys(friend);\n        if (keyValidationError) {\n          return Promise.reject(keyValidationError);\n        }\n      });\n\n      var urlParams = encodeObjectArray('friends', friends).join('&');\n      return this.__authPost('https://secure.splitwise.com/api/v3.0/create_friends?' + urlParams).then(function (data) {\n        return data['friends'];\n      });\n    }\n\n    /**\r\n     * Given a friend ID, break off the friendship between the current user and the specified user.\r\n     *\r\n     * @param friendId\r\n     * @returns {Promise<Error|Boolean>}\r\n     */\n\n  }, {\n    key: 'deleteFriend',\n    value: function deleteFriend(friendId) {\n      return this.__authPost('https://secure.splitwise.com/api/v3.0/delete_friend/' + friendId).then(function (data) {\n        return data['success'];\n      });\n    }\n\n    /**\r\n     * Returns an array of notifications\r\n     * @returns {Promise<Error|Array<Object>>}\r\n     */\n\n  }, {\n    key: 'getNotifications',\n    value: function getNotifications() {\n      return this.__authGet('https://secure.splitwise.com/api/v3.0/get_notifications').then(function (data) {\n        return data['notifications'];\n      });\n    }\n  }]);\n\n  return SplitwiseApi;\n}();\n\nmodule.exports = AuthApi;"]}