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oot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/node-notifymyandroid@1.0.1/lib/NotifyMyAndroid.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const querystring = require('querystring')\r\nconst request = require('request')\r\nconst parseString = require('xml2js').parseString\r\n\r\nexports.ENDPOINTS = {\r\n  'VERIFY': 'https://www.notifymyandroid.com/publicapi/verify',\r\n  'NOTIFY': 'https://www.notifymyandroid.com/publicapi/notify'\r\n}\r\n\r\n/**\r\n * @callback resultCallback\r\n * @param {Error} error - The error or null if not available.\r\n * @param {bool} success - Indicates whether the result had no errors.\r\n */\r\n\r\n/**\r\n * Notifier for Notify My Android.\r\n * @constructor\r\n * @param {string} applicationName - The name of the application that is generating the call.\r\n * @param {string} [developerKey] - Your developer key, if you have one. This is optional.\r\n */\r\nvar Notifier = function (applicationName, developerKey) {\r\n  var self = this\r\n  var remaining = {\r\n    calls: null,\r\n    date: null\r\n  }\r\n\r\n  /**\r\n   * Processes the remaining calls and minutes from the request.\r\n   * @param {string} calls - The remaining calls.\r\n   * @param {string} timer - The remaining minutes.\r\n   */\r\n  var processRemaining = function (calls, timer) {\r\n    remaining.calls = parseInt(calls)\r\n\r\n    var date = new Date()\r\n    date.setMinutes(date.getMinutes() + parseInt(timer))\r\n    remaining.date = date\r\n  }\r\n\r\n  /**\r\n   * Checks whether any remaining calls are available before the the limit is reset.\r\n   * @return {bool}\r\n   * @public\r\n   */\r\n  this.hasCallsRemaining = function () {\r\n    return (self.getRemainingTime() || 1) > 0 && (self.getRemainingCalls() || 1) > 0\r\n  }\r\n\r\n  /**\r\n   * Get remaining calls.\r\n   * @return {?number} - Number of remaining calls or null if unknown.\r\n   * @public\r\n   */\r\n  this.getRemainingCalls = function () {\r\n    return remaining.calls\r\n  }\r\n\r\n  /**\r\n   * Get remaining minutes before the limit is reset.\r\n   * @return {?number} - Number of remaining minutes or null if unknown.\r\n   * @public\r\n   */\r\n  this.getRemainingTime = function () {\r\n    return remaining.date ? Math.ceil((remaining.date - (new Date())) / 60000) : null\r\n  }\r\n\r\n  /**\r\n   * Checks whether the API key is valid.\r\n   * @param {string} apiKey - The api key that you want to test if it is valid.\r\n   * @param {resultCallback} callback\r\n   * @public\r\n   */\r\n  this.isValidKey = function (apiKey, callback) {\r\n    // Validate arguments\r\n    if (!apiKey || apiKey.length !== 48) return callback(new Error('API key needs to be 48 bytes long'))\r\n    if (developerKey && developerKey.length !== 48) return callback(new Error('Developer key needs to be 48 bytes long'))\r\n    if (!self.hasCallsRemaining()) return callback(new Error('Request limit reached. Limit will be reset within ' + self.getRemainingTime() + ' minutes'))\r\n\r\n    // Query string data\r\n    var data = {\r\n      apikey: apiKey\r\n    }\r\n    if (developerKey) data.developerkey = developerKey\r\n\r\n    // Send request\r\n    request(exports.ENDPOINTS.VERIFY + '?' + querystring.stringify(data), function (error, response, body) {\r\n      // Validate response\r\n      if (error) return callback(error)\r\n      if (response.statusCode !== 200) return callback(new Error('Received unexpected HTTP status code: ' + response.statusCode))\r\n\r\n      // Parse XML body\r\n      parseString(body, function (err, result) {\r\n        if (err) return callback(err)\r\n        if (result.nma.error && !result.nma.success) {\r\n          if (result.nma.error[0]['$']['code'] === 401) return callback(null, false)\r\n          return callback(new Error('API returned status code ' + result.nma.error[0]['$']['code'] + ': ' + result.nma.error[0]['_']))\r\n        }\r\n\r\n        processRemaining(result.nma.success[0]['$']['remaining'], result.nma.success[0]['$']['resettimer'])\r\n        return callback(null, true)\r\n      })\r\n    })\r\n  }\r\n\r\n  /**\r\n   * Send a notification.\r\n   * @param {string} apiKeys - API keys separated by commas. Each API key is a 48 bytes hexadecimal string. When using multiple keys, you will only get a failure respose if all of them are not valid.\r\n   * @param {string} event - The event that is being notified. Depending on your application, it can be a subject or a brief description.\r\n   * @param {string} description - The notification text. Depending on your application, it can be a body of the message or a full description.\r\n   * @param {object} [options]\r\n   * @param {number} [options.priority=0] - A priority level for this notification. This is optional and in the future will be used to change the way NMA alerts you.\r\n   * @param {string} [options.url] - An URL/URI can be attached to your notification. You can send URL's or URI's supported by your device. The user will be able to long-click the notification and choose to follow the attached URL/URI, launching the application that can handle it.\r\n   * @param {string} [options.contentType] - You can set this parameter to \"text/html\" while sending the notification, and the basic html tags below will be interpreted and rendered while displaying the notification: &lt;a href=\"...\"&gt;, &lt;b&gt;, &lt;big&gt;, &lt;blockquote&gt;, &lt;br&gt;, &lt;cite&gt;, &lt;dfn&gt;, &lt;div align=\"...\"&gt;, &lt;em&gt;, &lt;font size=\"...\" color=\"...\" face=\"...\"&gt;, &lt;h1&gt;, &lt;h2&gt;, &lt;h3&gt;, &lt;h4&gt;, &lt;h5&gt;, &lt;h6&gt;, &lt;i&gt;, &lt;p&gt;, &lt;small&gt;, &lt;strike&gt;, &lt;strong&gt;, &lt;sub&gt;, &lt;sup&gt;, &lt;tt&gt;, &lt;u&gt;.\r\n   * @param {resultCallback} callback\r\n   * @public\r\n   */\r\n  this.sendNotification = function (apiKeys, event, description, options, callback) {\r\n    if (!callback) {\r\n      // Make options optional\r\n      callback = options\r\n      options = {}\r\n    }\r\n\r\n    // Validate arguments\r\n    if (!apiKeys || apiKeys.split(',').some(function (apiKey) { return apiKey.length !== 48 })) return callback(new Error('API key needs to be 48 bytes long'))\r\n\r\n    // Validate API limits\r\n    if (!self.hasCallsRemaining()) return callback(new Error('Request limit reached. Limit will be reset within ' + self.getRemainingTime() + ' minutes'))\r\n\r\n    // POST data\r\n    var data = {\r\n      form: {\r\n        'apikey': apiKeys,\r\n        'application': applicationName,\r\n        'event': event,\r\n        'description': description,\r\n        'priority': options.priority || 0,\r\n        'developerkey': developerKey,\r\n        'url': options.url,\r\n        'content-type': options.contentType\r\n      }\r\n    }\r\n\r\n    // Send request\r\n    request.post(exports.ENDPOINTS.NOTIFY, data, function (error, response, body) {\r\n      // Validate response\r\n      if (error) return callback(error)\r\n      if (response.statusCode !== 200) return callback(new Error('Received unexpected HTTP status code: ' + response.statusCode))\r\n\r\n      // Parse XML body\r\n      parseString(body, function (err, result) {\r\n        if (err) return callback(err)\r\n        if (result.nma.error && !result.nma.success) return callback(new Error('API returned status code ' + result.nma.error[0]['$']['code'] + ': ' + result.nma.error[0]['_']))\r\n\r\n        processRemaining(result.nma.success[0]['$']['remaining'], result.nma.success[0]['$']['resettimer'])\r\n        return callback(null, true)\r\n      })\r\n    })\r\n  }\r\n}\r\n\r\nexports.Notifier = Notifier\r\n"]}