{"version":3,"sources":["jsdelivr-header.js","/npm/clash-of-clans-sdk-node@1.0.7/clash-of-clans-sdk-node.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACLA,MAAM,MAAQ,QAAQ,cAChB,QAAU,yCACV,cAAgB,UAChB,WAAa,gBACb,WAAa,kBACb,UAAY,kBAGlB,OAAO,QAAU,MAMf,WAAA,CAAY,EAAO,GACjB,OAAO,IAAI,SAAQ,MAAO,IACxB,KAAK,MAAQ,EACb,KAAK,SAAW,EAChB,KAAK,gBAAkB,WAEjB,KAAK,eACX,EAAQ,KAAK,GAEjB,CAEA,iBAAM,CAAY,EAAc,KAAM,EAAU,MAC9C,OAAO,MAAM,QAAU,EAAa,CAClC,QAAS,CACP,OAAU,MACV,kBAAmB,iBACnB,eAAgB,mBAChB,iBAAkB,QAClB,iBAAkB,OAClB,iBAAkB,cAClB,mBAAoB,iBACpB,OAAU,KAAK,gBAAkB,KAAK,gBAAkB,IAE1D,YAAe,cACf,SAAY,sCACZ,eAAkB,6BAClB,KAAQ,EAAU,KAAK,UAAU,GAAW,KAC5C,OAAU,OACV,KAAQ,QAEZ,CAGA,kBAAM,GACJ,IACE,MAAM,EAAU,CACd,MAAO,KAAK,MACZ,SAAU,KAAK,UAGX,QAAY,KAAK,YApDP,UAoDkC,GAClD,KAAK,gBAAkB,EAAI,QAAQ,IAAI,aACzC,CAAE,MAAO,GACP,OAAO,CACT,CACF,CAMA,gBAAM,GACJ,IAEE,aADkB,KAAK,YAAY,aACxB,MACb,CAAE,MAAO,GACP,OAAO,CACT,CACF,CAMA,kBAAM,CAAa,GACjB,IAEE,aADkB,KAAK,YAAY,WAAY,IACpC,MACb,CAAE,MAAO,GACP,OAAO,CACT,CACF,CAOA,eAAM,CAAU,GACd,IACE,MAAM,EAAU,CACd,GAAI,GAGN,aADkB,KAAK,YAAY,UAAW,IACnC,MACb,CAAE,MAAO,GACP,OAAO,CACT,CACF","file":"/npm/clash-of-clans-sdk-node@1.0.7/clash-of-clans-sdk-node.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/clash-of-clans-sdk-node@1.0.7/clash-of-clans-sdk-node.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\nconst fetch = require('node-fetch');\nconst apiBase = 'https://developer.clashofclans.com/api';\nconst loginEndpoint = '/login/';\nconst listTokens = '/apikey/list/';\nconst createKeys = '/apikey/create/';\nconst revokeKey = '/apikey/revoke/';\n\n\nmodule.exports = class ClashOfClansSDK {\n  /**\n   * @param {string} email Email for Clash of Clans Developer Account\n   * @param {string} password Password for Clash of Clans Developer Account\n   * @returns email, password and cookies\n   */\n  constructor(email, password) {\n    return new Promise(async (resolve) => {\n      this.email = email;\n      this.password = password;\n      this.responseCookies = null;\n\n      await this.authenticate();\n      resolve(this);\n    });\n  }\n\n  async postRequest(apiEndpoint = null, payload = null) {\n    return fetch(apiBase + apiEndpoint, {\n      headers: {\n        'accept': '*/*',\n        'accept-language': 'en-IN,en;q=0.9',\n        'content-type': 'application/json',\n        'sec-fetch-dest': 'empty',\n        'sec-fetch-mode': 'cors',\n        'sec-fetch-site': 'same-origin',\n        'x-requested-with': 'XMLHttpRequest',\n        'cookie': this.responseCookies ? this.responseCookies : ''\n      },\n      'credentials': 'same-origin',\n      'referrer': 'https://developer.clashofclans.com/',\n      'referrerPolicy': 'no-referrer-when-downgrade',\n      'body': payload ? JSON.stringify(payload) : '{}',\n      'method': 'POST',\n      'mode': 'cors'\n    })\n  }\n\n\n  async authenticate() {\n    try {\n      const payload = {\n        email: this.email,\n        password: this.password\n      };\n\n      const res = await this.postRequest(loginEndpoint, payload);\n      this.responseCookies = res.headers.get('set-cookie');\n    } catch (err) {\n      return err;\n    }\n  }\n\n  \n  /**\n   * @returns token object\n   */\n  async listTokens() {\n    try {\n      const res = await this.postRequest(listTokens);\n      return res.json();\n    } catch (err) {\n      return err;\n    } \n  }\n\n  /**\n   * @param {Object} key Payload for creating token\n   * @returns newly created key object\n   */\n  async createTokens(key) {\n    try {\n      const res = await this.postRequest(createKeys, key);\n      return res.json();\n    } catch (err) {\n      return err;\n    } \n  }\n\n\n  /**\n   * @param {string} keyId ID of a key which has to be deleted\n   * @returns status of delete\n   */\n  async deleteKey(keyId) {\n    try {\n      const payload = {\n        id: keyId\n      };\n      const res = await this.postRequest(revokeKey, payload);\n      return res.json();\n    } catch (err) {\n      return err;\n    } \n  }\n}\n"]}