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,cAC1B,WAAY,qBACZ,aAAc,EACd,KAAM,GAEJ,EAAO,GAAG,UAAU,GAExB,OAAO,KAAK,QAAQ,OArJO,sBAqJyB,CAClD,KAAM,EACN,QAAS,CACP,eAAgB,uCAEjB,MAAM,GAAQ,EAAI,MACvB,EAGF,OAAO,QAAU","file":"/npm/igram@3.0.0/instagram.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/igram@3.0.0/instagram.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\n// Module dependencies.\nconst url = require('url')\nconst got = require('got')\nconst qs = require('querystring')\nconst debug = require('debug')('insta:client')\n\n/**\n * @constant\n * @type {string}\n * @default\n */\n\nconst AUTH_AUTHORIZATION_PATH = '/oauth/authorize'\n\n/**\n * @constant\n * @type {string}\n * @default\n */\n\nconst AUTH_ACCESS_TOKEN_PATH = '/oauth/access_token'\n\n/**\n * @constant\n * @type {string[]}\n * @default\n */\n\nconst AUTH_PARAMS = ['client_id', 'client_secret', 'access_token']\n\n/**\n * Class representing Instagram client.\n */\n\nclass Instagram {\n  /**\n   * Create an instance.\n   *\n   * Authorization options can later be set\n   * with call to {@link Instagram#setAuth}.\n   *\n   * @param {Object} [options] Instance options.\n   * @param {string} [options.client_id] Client ID.\n   * @param {string} [options.client_secret] Client Secret.\n   * @param {string} [options.host=https://api.instagram.com] Instagram API endpoint.\n   */\n\n  constructor (options) {\n    options || (options = {})\n    this._host = options.host || 'https://api.instagram.com'\n    this._auth = {}\n    this.setAuth(options)\n  }\n\n  /**\n   * Set authorization parameters.\n   *\n   * @param {Object} options Authorization parameters.\n   * @param {string} [options.client_id] Client ID.\n   * @param {string} [options.client_secret] Client Secret.\n   *\n   * @returns {Instagram} This instance.\n   */\n\n  setAuth (options) {\n    AUTH_PARAMS.forEach((param) => {\n      if (typeof options[param] !== 'undefined') {\n        this._auth[param] = options[param]\n      }\n    })\n    return this\n  }\n\n  /**\n   * Get current authorization parameters.\n   *\n   * @returns {Object} Current authorization parameters.\n   */\n\n  getAuth () {\n    return Object.assign({}, this._auth)\n  }\n\n  /**\n   * Create request.\n   *\n   * @param {string} method HTTP method.\n   * @param {string} path Resource path.\n   * @param {Object} [options] Request options passed to\n   *   [Got]{@link https://github.com/sindresorhus/got#goturl-options}\n   *\n   * @returns {Promise<Object>} A promise resolving to response object.\n   */\n\n  request (method, path, options) {\n    options = Object.assign({\n      method: method,\n      path: path,\n      json: true\n    }, options)\n\n    debug('request: %s, %j', this._host, options)\n\n    return got(this._host, options)\n  }\n\n  /**\n   * Generate authorization URL.\n   *\n   * For more information see\n   * [Instagram Authentication]{@link https://www.instagram.com/developer/authentication/}.\n   *\n   * @param {string} redirectUri Redirect URI\n   * @param {Object} [options] Additional query parameters.\n   * @param {string} [options.state] Server specific state.\n   * @param {string|string[]} [options.scope] Additional permissions outside\n   *   of the \"basic\" permissions scope. See\n   *   [Instagram Authorization]{@link https://www.instagram.com/developer/authorization/}\n   *\n   * @returns {string} An authorization URL.\n   */\n\n  getAuthorizationUrl (redirectUri, options) {\n    if (!this._auth.client_id) {\n      throw new Error('Authorization parameter `client_id` not set')\n    }\n\n    let params = Object.assign({\n      client_id: this._auth.client_id,\n      redirect_uri: redirectUri,\n      response_type: 'code'\n    }, options)\n\n    if (Array.isArray(params.scope)) {\n      params.scope = params.scope.join('+')\n    }\n\n    let urlObj = url.parse(this._host)\n    urlObj.pathname = AUTH_AUTHORIZATION_PATH\n    urlObj.query = params\n\n    return url.format(urlObj)\n  }\n\n  /**\n   * Exchange authorization code for access token.\n   *\n   * @param {string} code Authorization code received from service.\n   * @param {string} redirectUri Redirect URI.\n   *\n   * @throws {Error}\n   *\n   * @returns {Promise<Object>} Response containing access token.\n   */\n\n  requestAccessToken (code, redirectUri) {\n    if (!this._auth.client_id || !this._auth.client_secret) {\n      throw new Error('Authorization parameters `client_id` and `client_secret` not set')\n    }\n\n    let params = {\n      client_id: this._auth.client_id,\n      client_secret: this._auth.client_secret,\n      grant_type: 'authorization_code',\n      redirect_uri: redirectUri,\n      code: code\n    }\n    let body = qs.stringify(params)\n\n    return this.request('POST', AUTH_ACCESS_TOKEN_PATH, {\n      body: body,\n      headers: {\n        'Content-Type': 'application/x-www-form-urlencoded'\n      }\n    }).then((res) => res.body)\n  }\n}\n\nmodule.exports = Instagram\n"]}