UNPKG

5 kBSource Map (JSON)View Raw
1{"version":3,"file":"index.js","sources":["../src/helpers.js","../src/postman-api.js"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nconst inquirer = require(\"inquirer\");\nconst os = require(\"os\");\nconst jsonfile = require(\"jsonfile\");\nconst homedir = os.homedir();\n\n/**\n * Get fastman config dir, if not exist, make it\n */\nexport function configDir() {\n const dir = path.join(homedir, \".fastman\");\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir);\n }\n return dir;\n}\n\n/**\n * set or rest api key in config file\n * @param apiKey postman api key, generated in https://docs.api.getpostman.com/?_ga=2.130537292.2138205523.1539075071-1493562217.1539075071#authentication\n */\nexport function writeConfig(config) {\n const dir = configDir();\n const configFile = path.join(dir, \"config.json\");\n const oldConfig = fs.existsSync(configFile)\n ? jsonfile.readFileSync(configFile)\n : {};\n jsonfile.writeFileSync(configFile, { ...oldConfig, ...config });\n}\n\nexport function getConfig() {\n const dir = configDir();\n const configFile = path.join(dir, \"config.json\");\n if (!fs.existsSync(configFile)) {\n return {};\n }\n return jsonfile.readFileSync(configFile);\n}\n\n/**\n * get stored api key, if api key not config, return undefinded\n * @returns api key or undefinded\n */\nexport function getApiKey() {\n const config = getConfig();\n return config.apiKey;\n}\n\n/**\n * check api key is exist\n */\nexport function checkApiKey() {\n return new Promise((resolve, reject) => {\n const apiKey = getApiKey();\n\n if (!apiKey) {\n inquirer\n .prompt([\n {\n name: \"apiKey\",\n message:\n \"Please input postman api key.\\n If has none, applay it in https://go.postman.co/integrations/services/pm_pro_api\",\n default: null,\n },\n ])\n .then(answers => {\n const apiKey = answers.apiKey;\n if (apiKey) {\n const config = getConfig();\n config.apiKey = apiKey;\n console.log(\"Api key has been saved!\");\n writeConfig(config);\n resolve(apiKey);\n }\n reject(\"Api key is empty!\");\n });\n } else {\n resolve(apiKey);\n }\n });\n}\n","import { getApiKey } from \"./helpers\";\nimport fetch from \"@36node/fetch\";\n\nfunction getHeaders() {\n const apiKey = getApiKey();\n return {\n \"X-Api-Key\": apiKey,\n };\n}\n\n/**\n * list collection use postman api\n */\nexport function listCollections() {\n return fetch(\"https://api.getpostman.com/collections\", {\n headers: getHeaders(),\n }).then(result => result.body.collections);\n}\n\n/**\n * get single collection\n * @param {string} id collection id\n */\nexport function singleCollection(id) {\n return fetch(`https://api.getpostman.com/collections/${id}`, {\n headers: getHeaders(),\n }).then(result => {\n return result.body.collection;\n });\n}\n\nexport function updateCollection(id, collection) {\n return fetch(`https://api.getpostman.com/collections/${id}`, {\n method: \"PUT\",\n headers: getHeaders(),\n body: { collection },\n }).then(result => result.body.collection);\n}\n\nexport function createCollection(collection) {\n return fetch(\"https://api.getpostman.com/collections\", {\n method: \"POST\",\n headers: getHeaders(),\n body: { collection },\n }).then(result => result.body.collection);\n}\n"],"names":["inquirer","require","os","jsonfile","homedir","configDir","dir","path","join","fs","existsSync","mkdirSync","writeConfig","config","configFile","oldConfig","readFileSync","writeFileSync","Object","getConfig","getApiKey","apiKey","getHeaders","fetch","headers","then","result","body","collections","id","collection","method","Promise","resolve","reject","prompt","name","message","default","answers","console","log"],"mappings":"gJAEMA,EAAWC,QAAQ,YACnBC,EAAKD,QAAQ,MACbE,EAAWF,QAAQ,YACnBG,EAAUF,EAAGE,UAKnB,SAAgBC,QACRC,EAAMC,EAAKC,KAAKJ,EAAS,mBAC1BK,EAAGC,WAAWJ,IACjBG,EAAGE,UAAUL,GAERA,EAOF,SAASM,EAAYC,OACpBP,EAAMD,IACNS,EAAaP,EAAKC,KAAKF,EAAK,eAC5BS,EAAYN,EAAGC,WAAWI,GAC5BX,EAASa,aAAaF,GACtB,GACJX,EAASc,cAAcH,EAAYI,iBAAKH,MAG1C,SAAgBI,QACRb,EAAMD,IACNS,EAAaP,EAAKC,KAAKF,EAAK,sBAC7BG,EAAGC,WAAWI,GAGZX,EAASa,aAAaF,GAFpB,GASX,SAAgBM,WACCD,IACDE,gBC3CPC,UAEA,aADQF,4BASjB,kBACSG,EAAM,yCAA0C,CAC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