UNPKG

1.72 kBJavaScriptView Raw
1function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var n=e(require("path")),t=e(require("fs")),o=e(require("@36node/fetch")),i=require("inquirer"),r=require("os"),c=require("jsonfile"),s=r.homedir();function a(){var e=n.join(s,".fastman");return t.existsSync(e)||t.mkdirSync(e),e}function l(e){var o=a(),i=n.join(o,"config.json"),r=t.existsSync(i)?c.readFileSync(i):{};c.writeFileSync(i,Object.assign({},r,e))}function u(){var e=a(),o=n.join(e,"config.json");return t.existsSync(o)?c.readFileSync(o):{}}function p(){return u().apiKey}function f(){return{"X-Api-Key":p()}}var y={listCollections:function(){return o("https://api.getpostman.com/collections",{headers:f()}).then(function(e){return e.body.collections})},singleCollection:function(e){return o("https://api.getpostman.com/collections/"+e,{headers:f()}).then(function(e){return e.body.collection})},updateCollection:function(e,n){return o("https://api.getpostman.com/collections/"+e,{method:"PUT",headers:f(),body:{collection:n}}).then(function(e){return e.body.collection})},createCollection:function(e){return o("https://api.getpostman.com/collections",{method:"POST",headers:f(),body:{collection:e}}).then(function(e){return e.body.collection})}};exports.helpers={configDir:a,writeConfig:l,getConfig:u,getApiKey:p,checkApiKey:function(){return new Promise(function(e,n){var t=p();t?e(t):i.prompt([{name:"apiKey",message:"Please input postman api key.\n If has none, applay it in https://go.postman.co/integrations/services/pm_pro_api",default:null}]).then(function(t){var o=t.apiKey;if(o){var i=u();i.apiKey=o,console.log("Api key has been saved!"),l(i),e(o)}n("Api key is empty!")})})}},exports.apis=y;
2//# sourceMappingURL=index.js.map