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Z,EAAO,KAAK,CACV,GAAI,EAAa,eACjB,KAAM,EAAa,iBACnB,UAAW,IAAI,KAAK,EAAa,mBAAmB,UAAY,IAChE,cAAe,EAAa,cAC5B,KAAM,EAAa,mBACnB,KAAM,KAAK,SAAS,iBAAmB,EAAa,QAAU,EAAa,YAC3E,KAA6B,SAAtB,EAAa,KACpB,WAAY,KACV,KAAK,wBAAwB,EAAa,eAAc,GAE3D,IAGH,EAAQ,EAAM,GACf,GAEL,EAOF,SAAS,YAEP,IAAK,KAAK,oBAAmC,IAAlB,KAAK,SAC9B,MAAM,MAAM,iKAAsK,KAAK,OAE3L,CAEA,OAAO,QAAU","file":"/npm/infinite-campus-api@1.0.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/infinite-campus-api@1.0.1/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","/*\r\n  This file conforms to the standardJS style (https://standardjs.com/)\r\n  This file is licensed under the GNU GPLv3 license (https://www.gnu.org/licenses/gpl-3.0.en.html)\r\n*/\r\n\r\n'use strict'\r\nvar request = require('request') // makes HTTP requests\r\nconst errHandler = require('./errPresets.js') // reqjs-err-handler error presets\r\nconst EventEmitter = require('events') // emit 'ready' event\r\n\r\nvar meta = {\r\n  version: '2.0.0',\r\n  github: 'qwazwsx/infinite-campus'\r\n}\r\n\r\n/*\r\n  Heres some basic vocab used to keep things consistent throughout naming and comments\r\n  term: a way of dividing up the school year. This may be by quarters, trimesters, semesters, etc.\r\n  course: a class\r\n  placement: the time within a day/term that a course takes place. Ex: 2nd hour at 9:15AM during quarter 1\r\n  notification count: the number of unseen notifications. This is the number that shows next to the bell icon on the website. The count is reset when you click the bell. NOTE: unseen is different from unread\r\n  (un)read notification: individual read state of a single notification. NOTE: read state is different from the unseen count\r\n*/\r\n\r\n// class definitions:\r\n\r\n/**\r\n  * @classdesc Represents a single course. All courses belong to a {@link Term}.\r\n  * @name Course\r\n  * @class\r\n\r\n  * @property {string} name\r\n  * @property {string} courseNumber\r\n  * @property {string} teacher\r\n  * @property {string} roomName\r\n  * @property {string} _id - unique id for the course\r\n\r\n  * @property {object} grades - grades for the course\r\n  * @property {number} grades.percent\r\n  * @property {number} grades.pointsEarned\r\n  * @property {string} grades.score - letter grade\r\n  * @property {number} grades.totalPoints\r\n\r\n  * @property {object} placement - when the class takes place\r\n  * @property {string} placement.startTime\r\n  * @property {string} placement.endTime\r\n  * @property {string} placement.periodName - the name of the period\r\n  * @property {string} placement.periodSeq  - the order of when the period takes place in the day\r\n\r\n  * @example\r\n  * {\r\n  *  \"name\": \"2 English II\",\r\n  *  \"courseNumber\": \"000703\",\r\n  *  \"teacher\": \"John Doe\",\r\n  *  \"roomName\": \"205B\",\r\n  *  \"_id\": \"6278079\",\r\n  *  \"grades\": {\r\n  *    \"score\": \"A-\",\r\n  *    \"percent\": 89.76,\r\n  *    \"totalPoints\": 227,\r\n  *    \"pointsEarned\": 207\r\n  *  },\r\n  *  \"placement\": {\r\n  *    \"periodName\": \"6\",\r\n  *    \"periodSeq\": 7,\r\n  *    \"startTime\": \"14:00:00\",\r\n  *    \"endTime\": \"15:00:00\"\r\n  *  }\r\n  * }\r\n  *\r\n*/\r\n\r\n/**\r\n  * @classdesc Represents a term. A term is a way of dividing up the school year. They may be organized as quarters, semesters, trimesters, etc. A term will have a start and end date, and will contain courses.\r\n  * @name Term\r\n  * @class\r\n\r\n  * @property {string} startDate\r\n  * @property {string} endDate\r\n  * @property {string} name\r\n  * @property {number} seq - Term sequence. Use this number if you want to sort terms. For example, in a school that uses quarters the first quarter would be `seq: 1` while the second quarter would be `seq: 2`.\r\n  * @property {Course[]} courses - array of courses contained in the term\r\n*/\r\n\r\n/**\r\n  * @classdesc Type representing a notification. A user might get a notification for many reasons, but they are mostly for attendance, course, and grade updates.\r\n  * @name Notification\r\n  * @class\r\n\r\n  * @property {string} id - unique notification id\r\n  * @property {string} link - link to redirect to when clicked\r\n  * @property {boolean} read - bool representing if the notification has been marked read or not\r\n  * @property {string} text - notification text\r\n  * @property {integer} timestamp - unix timestamp\r\n  * @property {string} timestampText - timestamp in text form\r\n  * @property {number} type - type of notification. The exact type definitions aren't known and more research has to be done. But right now the following is known:\r\n  * 2 - attendance updated (eg. you get marked tardy), 3 - course grade updated (eg. your class grade changes after an assignment is graded), 4 - assignment updated\r\n  * (eg. an assignment is graded or its state is updated as missing, late, etc )\r\n*/\r\n\r\n/**\r\n * @method toggleRead\r\n * @memberOf Notification\r\n * @instance\r\n * @description Toggles the read state of a notification\r\n * @example\r\n * const InfiniteCampus = require('infinite-campus')\r\n * const user = new InfiniteCampus('New York District', 'NY', 'JDoe12', 'XXXXXX')\r\n *\r\n *  // wait until we are done logging in\r\n *  user.on('ready', () => {\r\n *    // user is authenticated, now we can get notifications\r\n *    user.getNotifications().then((notifications) => {\r\n *      // if the first notification is unread\r\n *      if (notification[0].read === false){\r\n *        // mark it as read by toggling its read state\r\n *        notifications[0].toggleRead()\r\n *      }\r\n *    }\r\n *  })\r\n */\r\n\r\n/**\r\n * Class representing an authenticated Infinite Campus user\r\n */\r\nclass User extends EventEmitter {\r\n  /**\r\n   * Fired when the user is authenticated and ready to make API calls\r\n   * @event User#ready\r\n   */\r\n\r\n  /**\r\n   * Fired when the login process has failed\r\n   * @event User#error\r\n   */\r\n\r\n  /**\r\n    * Authenticates a user. Fires [ready]{@link User#event:ready} event when the user is logged in\r\n    * ##### Example: <br>\r\n    * <pre><code class=\"prettyprint\">const InfiniteCampus = require('infinite-campus')\r\n    * const user = new InfiniteCampus('New York District', 'NY', 'JDoe12', 'XXXXXX')\r\n    *\r\n    * user.on('ready', () => {\r\n    *   // user is authenticated, now we can make API calls\r\n    * })</code></pre>\r\n    * @param {string} districtName - the name of the district the user belongs to (ex: 'New York School Districts', 'New York')\r\n    * @param {string} state - two letter state code ('NY', 'MN')\r\n    * @param {username} - the user's username\r\n    * @param {password} - the user's password\r\n    * @fires User#ready\r\n    * @async\r\n\r\n  */\r\n\r\n  constructor(districtName, state, username, password) {\r\n    super() // calls EventEmitter constructor\r\n    this.meta = meta\r\n    this.authenticated = false\r\n    this.cookies = request.jar()\r\n    request = request.defaults({\r\n      jar: this.cookies,\r\n      headers: {\r\n        'User-Agent': `GitHub ${meta.github} - v${meta.version}`,\r\n        'Accept': 'application/json'\r\n      }\r\n    })\r\n\r\n    // detect login errors thrown\r\n    // if there is a listener on 'error' event, emit it, else throw the error and kill the process\r\n    this.on('error', (err) => {\r\n      if (!this.hasErrorListener) {\r\n        throw err\r\n      }\r\n    })\r\n\r\n    // check to see if anybody is listening on 'error'\r\n    this.hasErrorListener = false\r\n    this.once('newListener', (event) => {\r\n      if (event === 'error') {\r\n        this.hasErrorListener = true\r\n      }\r\n    })\r\n\r\n    // fetch district info & log in\r\n    this._getDistrict(districtName, state).then(() => {\r\n      // weird return promise to avoid minor callback hell\r\n      return this._login(username, password)\r\n    }).then(() => {\r\n      // once we are logged in\r\n      this.authenticated = true\r\n      this.emit('ready', this)\r\n    }).catch((err) => {\r\n      // this error should never actually get thrown\r\n      // if it does, it means either 1.) the API has changed and we cant parse it 2.) there is some unexpected value and it broke with my code\r\n      throw Error('Unknown error during the getDistrict/login process. If you keep getting this error please submit an issue on GitHub @' + meta.github + '\\n ' + err)\r\n    })\r\n  }\r\n\r\n  /**\r\n    * fetches information about a school district thats needed to make requests\r\n    * this data is stored in the this.district object\r\n    * @param {string} districtName - the name of the district the user belongs to (ex: 'New York School Districts', 'New York')\r\n    * @param {string} state - two letter state code (ex: 'NY', 'MN')\r\n    * @async\r\n    * @private\r\n\r\n  */\r\n  _getDistrict(districtName, state) {\r\n    return new Promise((resolve, reject) => {\r\n      request('https://mobile.infinitecampus.com/mobile/searchDistrict?query=' + districtName + '&state=' + state, (err, res, body) => {\r\n        try {\r\n          errHandler.district.handle(err, res, body)\r\n        } catch (err) {\r\n          return this.emit('error', err)\r\n        }\r\n\r\n        this.district = JSON.parse(body).data[0]\r\n        resolve()\r\n      })\r\n    })\r\n  }\r\n\r\n  /**\r\n   * logs a user in\r\n   * cookies get stored as a requestJS cookie jar in this.cookies\r\n   * @param {string} username - a user's username\r\n   * @param {string} password - a user's password\r\n   * @async\r\n   * @private\r\n   */\r\n  _login(username, password) {\r\n    return new Promise((resolve, reject) => {\r\n      if (this.district === undefined) {\r\n        throw Error('._getDistrict() must be ran before you can log in.')\r\n      }\r\n\r\n      request(this.district.district_baseurl + 'verify.jsp?nonBrowser=true&username=' + username + '&password=' + password + '&appName=' + this.district.district_app_name, (err, res, body) => {\r\n        try {\r\n          errHandler.login.handle(err, res, body)\r\n        } catch (err) {\r\n          return this.emit('error', err)\r\n        }\r\n\r\n        resolve()\r\n      })\r\n    })\r\n  }\r\n\r\n  /**\r\n   * Fetches data for all courses a user is enrolled in. This method returns information about all terms, all courses, all grades for those courses,\r\n   * as well as all time placement data for those courses. See documentation for the [Term]{@link Term} and [Course]{@link Course} types for more information on what this method specifically returns. <br>\r\n   * @async\r\n   * @returns {Term[]} array of terms containing courses\r\n   * @example\r\n   * const InfiniteCampus = require('infinite-campus')\r\n   * const user = new InfiniteCampus('New York District', 'NY', 'JDoe12', 'XXXXXX')\r\n   *\r\n   * // wait until we are done logging in\r\n   * user.on('ready', () => {\r\n   *   // now that we are logged in, fetch courses\r\n   *   user.getCourses().then((courses) => {\r\n   *     console.log(courses)\r\n   *   })\r\n   * })\r\n   *\r\n   */\r\n  getCourses(schoolID) {\r\n    return new Promise((resolve, reject) => {\r\n      checkAuth.call(this)\r\n      // fetch roster with placements\r\n      request(this.district.district_baseurl + 'resources/portal/roster?_expand=%7BsectionPlacements-%7Bterm%7D%7D', (err, res, body) => {\r\n        errHandler.generic200.handle(err, res, body)\r\n        let roster = JSON.parse(body)\r\n\r\n        // fetch grades\r\n        request(this.district.district_baseurl + 'resources/portal/grades', (err, res, body) => {\r\n          errHandler.generic200.handle(err, res, body)\r\n          let grades = JSON.parse(body)\r\n\r\n          let result = [] // object that we return later\r\n          let crossReference = {}\r\n\r\n          let schoolIndex\r\n\r\n          // if we are enrolled in multiple schools\r\n          if (grades.length > 1) {\r\n            // build list of schools\r\n            let schools = []\r\n            grades.forEach((school) => {\r\n              schools.push({\r\n                schoolName: school.displayName,\r\n                id: school.schoolID,\r\n                numberOfTerms: school.terms.length,\r\n                totalNumberOfCourses: school.courses.length\r\n              })\r\n            })\r\n\r\n            // throw warning is schoolID isn't specifed\r\n            if (schoolID === undefined) {\r\n              console.warn(`WARNING: You are enrolled in ${grades.length} schools, please explicitly specify a school ID to fetch courses from. Please see the below output to see which schoolID to use. (Defaulting to the first school returned by I.C. API - name: '${schools[0].schoolName}' - id: ${schools[0].id})`, schools)\r\n              // default to first in array\r\n              schoolIndex = 0\r\n            } else {\r\n              // find index from schoolID\r\n              grades.forEach((school, i) => {\r\n                if (school.schoolID == schoolID) {\r\n                  schoolIndex = i\r\n                }\r\n              })\r\n              if (schoolIndex === undefined) {\r\n                throw new Error(`Supplied schoolID in getCourses() does not exist, please select from the following list \\n\\n ${JSON.stringify(schools)}\\n\\n`)\r\n              }\r\n            }\r\n\r\n          }\r\n\r\n          // loop over terms from /grades\r\n          if (!schoolIndex) {\r\n            schoolIndex = 0\r\n          }\r\n          grades[schoolIndex].terms.forEach((term, i) => {\r\n            let termResult = {\r\n              name: term.termName,\r\n              seq: term.termSeq,\r\n              startDate: term.startDate,\r\n              endDate: term.endDate,\r\n              courses: []\r\n            }\r\n\r\n            // loop over classes in a term\r\n            term.courses.forEach((course, ii) => {\r\n              let grade = course.gradingTasks[0]\r\n\r\n              let courseResult = {\r\n                name: course.courseName,\r\n                courseNumber: course.courseNumber,\r\n                roomName: course.roomName,\r\n                teacher: course.teacherDisplay,\r\n                // seq: null, // set this to null so we can add placement data later\r\n                grades: {\r\n                  score: (grade.progressScore !== undefined) ? grade.progressScore : grade.score,\r\n                  percent: (grade.progressPercent !== undefined) ? grade.progressPercent : grade.percent,\r\n                  totalPoints: (grade.progressTotalPoints !== undefined) ? grade.progressTotalPoints : grade.totalPoints,\r\n                  pointsEarned: (grade.progressPointsEarned !== undefined) ? grade.progressPointsEarned : grade.pointsEarned\r\n                },\r\n                comments: grade.comments,\r\n                _id: course._id\r\n              }\r\n\r\n              // remove grades for courses without grades\r\n              if (!(grade.progressScore || grade.score) &&\r\n                !(grade.progressPercent || grade.percent) &&\r\n                !(grade.progressTotalPoints || grade.totalPoints) &&\r\n                !(grade.progressPointsEarned || grade.pointsEarned)) courseResult.grades = undefined;\r\n\r\n              // push class to term array\r\n              termResult.courses.push(courseResult)\r\n\r\n              // setup cross reference with a pointer into the result var\r\n              // we can cross reference the data from both endpoints by using the class ID later\r\n              crossReference[course._id] = {\r\n                i: i,\r\n                ii: ii\r\n              }\r\n            })\r\n\r\n            // push terms to final array\r\n            result.push(termResult)\r\n          })\r\n\r\n          /*\r\n            At this point we have basic info about terms and a bit data on the classes (name, teacher, grade). But we don't have any placement data (period, start & end time, sequence data) for courses or for terms.\r\n            So now we look over the data from the /roster endpoint and use our cross reference object to add the missing data. We loop over the data (an array of courses) and check the class ID with our cross reference.\r\n            That gives us a pointer into the result array so we can add the data in. We add class placement data into courses and check to see if we need to add term data (this is because the term object is included in every course)\r\n          */\r\n          // loop over classes from /roster\r\n          \r\n          var resTemp = []\r\n          roster.forEach((course, i) => {            \r\n            var classSchedule = {}\r\n            course.sectionPlacements.forEach((placement) => {\r\n              if (!classSchedule[placement.courseName]) {\r\n                classSchedule[placement.courseName] = {}\r\n                classSchedule[placement.courseName][placement.termName] = {\r\n                  [placement.periodScheduleName] : placement.periodName\r\n                }}\r\n              else{\r\n                if (!classSchedule[placement.courseName][placement.termName]) {\r\n                  classSchedule[placement.courseName][placement.termName] = {\r\n                    [placement.periodScheduleName] : placement.periodName\r\n                }}\r\n                else {\r\n                  classSchedule[placement.courseName][placement.termName][placement.periodScheduleName]=placement.periodName\r\n                }\r\n              }\r\n            })\r\n\r\n            // find course from cross reference\r\n            let ref = crossReference[roster[i]._id]\r\n            if (!ref) return\r\n            let target = result[ref.i].courses[ref.ii]\r\n            /* Logging the first element of the array, which is the first object in the array. */\r\n            // console.log(classSchedule)\r\n            // console.log('###################')\r\n            // console.log(target)\r\n            // console.log('###################')\r\n            \r\n            // add placement data\r\n            target.placement = classSchedule\r\n            resTemp.push(target)\r\n          })\r\n          result.forEach((terms) => {\r\n            var termName = terms.name\r\n            // console.log(terms)\r\n            terms.courses.forEach((course) => {\r\n              // console.log(resTemp)\r\n              resTemp.forEach((courseTemp) => {\r\n                if (courseTemp.name == course.name) {\r\n                  course.placement = courseTemp.placement[course.name][termName]\r\n                }\r\n              })\r\n              // course.placement = resTemp[course.name][termName]\r\n            })\r\n            \r\n          })\r\n          \r\n\r\n\r\n          // result.forEach((terms) => {\r\n          //   var termName = terms.name\r\n          //   resTemp.forEach((course) => {\r\n              \r\n          // //     // console.log(course)\r\n          //     if (course.placement[course.name][termName]) {\r\n          //       // console.log(course.name, termName, course.placement[course.name][termName])\r\n          //       terms.courses.forEach((course2) => {\r\n          //         if (course2.name == course.name) {\r\n          //           course2.placement = course.placement[course.name][termName]\r\n          //         }\r\n          //       // console.log(course2)\r\n          //       })\r\n                \r\n          //     }\r\n            // console.log(termName)\r\n            // terms.forEach((term) => {\r\n            //   console.log(term.name)\r\n            // })\r\n          // })\r\n\r\n\r\n          // result = resTemp\r\n          // console.log(result)\r\n\r\n\r\n          resolve(result)\r\n        })\r\n      })\r\n    })\r\n  }\r\n\r\n  /**\r\n   * gets current number of unseen notifications <br>\r\n   * *note: the unseen notification count is different from the read status of an individual notification*\r\n   * @async\r\n   * @returns {integer} number of unseen notifications\r\n   * @example\r\n   * const InfiniteCampus = require('infinite-campus')\r\n   * const user = new InfiniteCampus('New York District', 'NY', 'JDoe12', 'XXXXXX')\r\n   *\r\n   * // wait until we are done logging in\r\n   * user.on('ready', () => {\r\n   *   // now that we are logged in, get the notification count\r\n   *   user.getNotificationCount().then((count) => {\r\n   *     console.log(count) // returns: 7\r\n   *   })\r\n   * })\r\n   *\r\n   */\r\n  getNotificationCount() {\r\n    return new Promise((resolve, reject) => {\r\n      checkAuth.call(this)\r\n      request(this.district.district_baseurl + 'prism?x=notifications.NotificationUser-countUnviewed', (err, res, body) => {\r\n        errHandler.generic200.handle(err, res, body)\r\n        resolve(parseInt(JSON.parse(body).data.RecentNotifications.count))\r\n      })\r\n    })\r\n  }\r\n\r\n  /**\r\n   * resets the unseen notification count. This is what happens when you click on the bell icon in Infinite Campus <br>\r\n   * *note: this is different from the read status of individual notifications, see [User.markAllNotificationsRead()]{@link User#markAllNotificationsRead} and [Notification.toggleRead()]{@link Notification#toggleRead}*\r\n   * @async\r\n   * @example\r\n   * const InfiniteCampus = require('infinite-campus')\r\n   * const user = new InfiniteCampus('New York District', 'NY', 'JDoe12', 'XXXXXX')\r\n   *\r\n   * // wait until we are done logging in\r\n   * user.on('ready', () => {\r\n   *   // now that we are logged in, reset the notification count\r\n   *   user.resetNotificationCount().then(() => {\r\n   *     // ...\r\n   *   })\r\n   * })\r\n   *\r\n   */\r\n  resetNotificationCount() {\r\n    return new Promise((resolve, reject) => {\r\n      checkAuth.call(this)\r\n      request(this.district.district_baseurl + 'prism?x=notifications.NotificationUser-updateLastViewed', (err, res, body) => {\r\n        errHandler.generic200.handle(err, res, body)\r\n        resolve()\r\n      })\r\n    })\r\n  }\r\n\r\n  /**\r\n   * marks all notifications as read <br>\r\n   * *note: this is different from the unread count, see [User.getNotificationCount()]{@link User#getNotificationCount} and [User.resetNotificationCount()]{@link User#resetNotificationCount}*\r\n   * @async\r\n   * @example\r\n   * const InfiniteCampus = require('infinite-campus')\r\n   * const user = new InfiniteCampus('New York District', 'NY', 'JDoe12', 'XXXXXX')\r\n   *\r\n   * // wait until we are done logging in\r\n   * user.on('ready', () => {\r\n   *   // now that we are logged in, mark all notifications as read\r\n   *   user.markAllNotificationsRead().then(() => {\r\n   *     // ...\r\n   *   })\r\n   * })\r\n   *\r\n   */\r\n  markAllNotificationsRead() {\r\n    return new Promise((resolve, reject) => {\r\n      checkAuth.call(this)\r\n      request(this.district.district_baseurl + 'prism?x=notifications.Notification-markAllRead', (err, res, body) => {\r\n        errHandler.generic200.handle(err, res, body)\r\n        resolve()\r\n      })\r\n    })\r\n  }\r\n\r\n  /**\r\n   * toggles a given notifications read state\r\n   * *note: this is different from the unread count, see [User.getNotificationCount()]{@link User#getNotificationCount} and [User.resetNotificationCount()]{@link User#resetNotificationCount}* <br>\r\n   * this function is included in {@link Notification}. For readability this function is private and a dock\r\n   * @async\r\n   * @private\r\n   */\r\n  _toggleNotificationRead(id) {\r\n    return new Promise((resolve, reject) => {\r\n      checkAuth.call(this)\r\n      request(this.district.district_baseurl + 'prism?x=notifications.Notification-toggleRead&notificationID=' + id, (err, res, body) => {\r\n        errHandler.generic200.handle(err, res, body)\r\n        resolve()\r\n      })\r\n    })\r\n  }\r\n\r\n  /**\r\n   * Returns a list of notifications. <br>\r\n   * ###### notification types: <br>\r\n   * keep in mind mind that that this data may not be 100% accurate, more research needs to be done <br>\r\n   * * 2 - attendance updated (eg. you get marked tardy) <br>\r\n   * * 3 - course grade updated (eg. your class grade changes after an assignment is graded) <br>\r\n   * * 4 - assignment updated (eg. an assignment is graded or its state is updated as missing, late, etc )\r\n   * @async\r\n   * @param {integer} [limit=200] - number of notifications to return\r\n   * @returns {Notification[]} array of notifications\r\n   * @example\r\n   * // this example will mark all notifications before certain date as read\r\n   *\r\n   * // first we log in\r\n   * const InfiniteCampus = require('infinite-campus')\r\n   * const user = new InfiniteCampus('New York District', 'NY', 'JDoe12', 'XXXXXX')\r\n   *\r\n   * // wait until we are done logging in\r\n   * user.on('ready', () => {\r\n   *   // now that we are logged in, get notifications\r\n   *   user.getNotifications().then((notifications) => {\r\n   *     console.log(notifications)\r\n   *   })\r\n   * })\r\n   *\r\n   */\r\n  getNotifications(limit) {\r\n    return new Promise((resolve, reject) => {\r\n      checkAuth.call(this)\r\n\r\n      if (typeof limit !== 'number') {\r\n        throw new Error(`[User.getNotifications(${limit})] 'limit' argument must be a number, got '${typeof limit}'`)\r\n      }\r\n      // if limit isn't set, default to 200\r\n      limit = limit === undefined ? 200 : limit\r\n      request(this.district.district_baseurl + 'prism?x=notifications.Notification-retrieve&limitCount=' + limit, (err, res, body) => {\r\n        errHandler.generic200.handle(err, res, body)\r\n        // console.log(body)\r\n        body = JSON.parse(body).data.NotificationList.Notification\r\n\r\n        let result = []\r\n\r\n        // loop over every assignment\r\n        body.forEach((notification) => {\r\n          result.push({\r\n            id: notification.notificationID,\r\n            text: notification.notificationText,\r\n            timestamp: new Date(notification.creationTimestamp).getTime() / 1000, // convert text to unix ms to s\r\n            timestampText: notification.displayedDate,\r\n            type: notification.notificationTypeID,\r\n            link: this.district.district_baseurl + notification.linkUrl + notification.linkContext,\r\n            read: (notification.read === 'true'),\r\n            toggleRead: () => {\r\n              this._toggleNotificationRead(notification.notificationID)\r\n            }\r\n          })\r\n        })\r\n\r\n        resolve(result)\r\n      })\r\n    })\r\n  }\r\n}\r\n\r\n/**\r\n * helper function to make sure a user is authenticated before making API calls\r\n * @private\r\n */\r\nfunction checkAuth() {\r\n  // checks if the user has been authenticated\r\n  if (!this.authenticated || this.district === undefined) {\r\n    throw Error('User isn\\'t authenticated yet. Please use the .on(\\'ready\\') event emitted by the User class. For help please see the example code on GitHub: https://github.com/' + meta.github)\r\n  }\r\n}\r\n\r\nmodule.exports = User\r\n\r\n// debugging:\r\n// keep debugger alive\r\n// setInterval(() => { console.log('keep alive') }, 100000000)\r\n\r\n// this is just plain stupid:\r\n// process.on('uncaughtException', function (err) {\r\n//   console.log('Caught exception: ' + err)\r\n// })\r\n"]}