@northflank/cli
Version:
Provides a command-line interface to the Northflank platform.
1 lines • 14.2 kB
JavaScript
;const a2P=a2K;function a2K(Z,K){const O=a2Z();return a2K=function(g,N){g=g-0x11b;let H=O[g];return H;},a2K(Z,K);}(function(Z,K){const Y=a2K,O=Z();while(!![]){try{const g=parseInt(Y(0x150))/0x1*(parseInt(Y(0x17f))/0x2)+parseInt(Y(0x1a1))/0x3+-parseInt(Y(0x181))/0x4+parseInt(Y(0x144))/0x5+-parseInt(Y(0x1b7))/0x6*(-parseInt(Y(0x121))/0x7)+parseInt(Y(0x14e))/0x8*(parseInt(Y(0x1bb))/0x9)+-parseInt(Y(0x1a2))/0xa;if(g===K)break;else O['push'](O['shift']());}catch(N){O['push'](O['shift']());}}}(a2Z,0x6f63b));var __createBinding=this&&this[a2P(0x192)]||(Object['create']?function(Z,K,O,g){const C=a2P;if(g===undefined)g=O;var N=Object[C(0x16b)](K,O);(!N||(C(0x182)in N?!K[C(0x180)]:N[C(0x165)]||N['configurable']))&&(N={'enumerable':!![],'get':function(){return K[O];}}),Object[C(0x162)](Z,g,N);}:function(Z,K,O,g){if(g===undefined)g=O;Z[g]=K[O];}),__setModuleDefault=this&&this[a2P(0x1aa)]||(Object[a2P(0x13f)]?function(Z,K){const S=a2P;Object[S(0x162)](Z,S(0x136),{'enumerable':!![],'value':K});}:function(Z,K){const n=a2P;Z[n(0x136)]=K;}),__importStar=this&&this[a2P(0x133)]||function(Z){const k=a2P;if(Z&&Z[k(0x180)])return Z;var K={};if(Z!=null){for(var O in Z)if(O!==k(0x136)&&Object[k(0x153)][k(0x12c)][k(0x199)](Z,O))__createBinding(K,Z,O);}return __setModuleDefault(K,Z),K;},__awaiter=this&&this[a2P(0x16f)]||function(Z,K,O,g){function N(H){return H instanceof O?H:new O(function(o){o(H);});}return new(O||(O=Promise))(function(H,o){const r=a2K;function s(W){const x=a2K;try{y(g[x(0x18d)](W));}catch(B){o(B);}}function R(W){try{y(g['throw'](W));}catch(B){o(B);}}function y(W){const m=a2K;W['done']?H(W[m(0x11d)]):N(W[m(0x11d)])[m(0x15c)](s,R);}y((g=g[r(0x138)](Z,K||[]))['next']());});},__importDefault=this&&this[a2P(0x159)]||function(Z){return Z&&Z['__esModule']?Z:{'default':Z};};Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports[a2P(0x11e)]=void 0x0;function a2Z(){const t=['test','replace','name','InquirerHelper','__setModuleDefault','Shows\x20full\x20context\x20information\x20(including\x20tokens)','No\x20project\x20in\x20current\x20context.\x20Please\x20set\x20project\x20before\x20setting\x20a\x20project-scoped\x20resource','Update\x20token\x20for\x20current\x20context','remove','../inquirer-helper','verifyToken','map','askForService','clearLine','Retrieve\x20and\x20update\x20local\x20context\x20settings.','Use\x20browser\x20login\x20but\x20only\x20print\x20URL\x20which\x20can\x20be\x20used\x20to\x20login','contextAvailable','12LbgDxV','getInfo','Project\x20name\x20(internal\x20id)\x20to\x20use\x20as\x20default\x20in\x20context','Failed\x20to\x20login\x20with\x20the\x20provided\x20token.\x20Token\x20was\x20not\x20changed','8451UXUtia','Change\x20current\x20context\x20to\x20context\x20identified\x20by\x20this\x20name','Bearer\x20','Connect\x20the\x20CLI\x20to\x20your\x20Northflank\x20account.','contextProvider','value','CliContext','error','Name\x20for\x20login\x20context','1670221RCrBas','action','useJobId','service','defaultBaseUrl','finally','Local\x20context\x20name\x20to\x20remove.','\x20(api\x20host:\x20','Failed\x20to\x20login\x20with\x20the\x20provided\x20token,\x20make\x20sure\x20to\x20use\x20a\x20valid\x20token\x20and\x20host.','list','search-list','hasOwnProperty','--token-login','ProxyAgent','alias','project','Change\x20the\x20default\x20project\x20in\x20the\x20current\x20local\x20context','-i,\x20--id\x20[ID]','__importStar','success','\x20(current)','default','token','apply','addContext','getCurrentBaseUrl','set','tokenPrompt','moveCursor','No\x20context\x20available.\x20Please\x20use\x20\x27northflank\x20login\x27\x20to\x20create\x20context.','create','removeContext','all','use','chalk','3201475SQWCSK','apiTokenLogin','getProjectName','browser-opened','Use\x20job\x20with\x20id:','message','askForContext','--host\x20[HOST]','-t,\x20--token\x20[TOKEN]','Token\x20for\x20this\x20context.\x20When\x20set,\x20browser\x20login\x20is\x20not\x20used','1624vqYQGa','context','3233fhXMUV','useServiceId','getCommand','prototype','Open\x20this\x20URL\x20in\x20your\x20browser\x20and\x20follow\x20the\x20steps:\x0a\x09','sessionToken=********','description','sort','prompt','__importDefault','valueOf','useContext','then','node-fetch','getCurrentContext','Token\x20for\x20this\x20context','dir','useProjectId','defineProperty','loginPrompt','Follow\x20the\x20steps\x20displayed\x20on\x20the\x20page\x20opened\x20in\x20the\x20browser\x20(URL\x20opened:\x20','writable','current','log','Job\x20name\x20(internal\x20id)\x20to\x20use\x20as\x20default\x20in\x20context','apiClient','use\x20from\x20now\x20on','getOwnPropertyDescriptor','length','autologin-','Changed\x20current\x20context\x20to\x20','__awaiter','browser\x20login','Use\x20manual\x20login\x20with\x20API\x20token','Remove\x20a\x20context','Change\x20the\x20default\x20service\x20in\x20the\x20current\x20local\x20context','https://api.northflank.com','host','Change\x20the\x20default\x20job\x20in\x20the\x20current\x20local\x20context','ctx','contexts','doNotOpenBrowser','Contexts','sanitiseHostname','getCurrentName','host\x20url\x20for\x20this\x20context','Use\x20project\x20with\x20id:','236nBHkku','__esModule','3277056KQYjya','get','proxy-agent',',\x20added\x20context\x20with\x20name\x20','loadContextWrapper','override','https://','List\x20all\x20available\x20contexts','Use\x20service\x20with\x20id:','agent','--do-not-open-browser','stdout','next','delete','login','askForJob','No\x20context\x20available.\x20Use\x20\x27northflank\x20login\x27\x20to\x20create\x20context.','__createBinding','warning','addCommand','/v1/login','option','browserLogin','.\x20Using\x20fallback.','call','startLogin','token\x20login','../utils','Service\x20name\x20(internal\x20id)\x20to\x20use\x20as\x20default\x20in\x20context','set-token','timeout','job','2559882sFvcoG','12673910kuIjGM','--all','GET','updateToken'];a2Z=function(){return t;};return a2Z();}const _=__importStar(require('lodash')),proxy_agent_1=require(a2P(0x183)),chalk_1=__importDefault(require(a2P(0x143))),utils_1=require(a2P(0x19c)),inquirer_helper_1=require(a2P(0x1af)),console_format_helpers_1=require('../formatting/console-format-helpers'),browser_login_1=require('../login/browser-login'),node_fetch_1=__importDefault(require(a2P(0x15d))),inquirer=require('inquirer');class CliContext{constructor(Z,K=undefined,O=a2P(0x174)){const D=a2P;this[D(0x18a)]=K,this['defaultBaseUrl']=O,this['sanitiseHostname']=V=>{const d=D;let M=V;return!/^https?:\/\//i[d(0x1a6)](M)&&(M=d(0x187)+M),M=M[d(0x1a7)](/\/+$/,''),M;},this['apiClient']=Z;const g=new inquirer_helper_1[(D(0x1a9))](Z);this[D(0x18f)]=(0x0,utils_1[D(0x152)])()[D(0x1a8)](D(0x18f))['description'](D(0x11b))['option'](D(0x12d),D(0x171),![])[D(0x196)](D(0x18b),D(0x1b5),![])[D(0x196)]('-n,\x20--name\x20[NAME]',D(0x120))[D(0x196)](D(0x14c),D(0x14d))['option'](D(0x14b),D(0x17d),this[D(0x125)])['option']('--override','Override\x20existing\x20contexts\x20(this\x20will\x20remove\x20project\x20and\x20service\x20context)',![])['action'](V=>__awaiter(this,void 0x0,void 0x0,function*(){const b=D;_[b(0x13b)](V,b(0x175),this[b(0x17b)](V[b(0x175)]));const M=V['tokenLogin']||V[b(0x137)]!==undefined,{name:I,host:c,token:E,override:p}=M?yield this[b(0x145)](V,g):yield this[b(0x197)](V,g);try{yield this[b(0x169)][b(0x11c)][b(0x139)]({'name':I,'host':c,'token':E},p);}catch(T){(0x0,utils_1[b(0x11f)])(T[b(0x149)]);return;}if(!(yield this[b(0x1b0)]()))(0x0,utils_1[b(0x11f)])(b(0x129)),yield this[b(0x169)][b(0x11c)][b(0x140)](I);else{const J=M?b(0x19b):b(0x170),q='\x0aSuccessfully\x20logged\x20in\x20using\x20'+J+b(0x184)+chalk_1[b(0x136)]['italic'](I)+b(0x128)+c+')';(0x0,utils_1['success'])(q);}})),this[D(0x178)]=(0x0,utils_1['getCommand'])()['name'](D(0x14f))[D(0x156)](D(0x1b4))[D(0x12f)](D(0x178))[D(0x12f)](D(0x177));const N=(0x0,utils_1[D(0x152)])()[D(0x1a8)]('list')['name']('ls')[D(0x156)](D(0x188))[D(0x196)](D(0x1a3),D(0x1ab))[D(0x122)](V=>__awaiter(this,void 0x0,void 0x0,function*(){const l=D;console[l(0x167)](Z['contextProvider'][l(0x1b8)]());const M=Z['contextProvider'][l(0x185)]();if(V[l(0x141)]===!![]){console[l(0x160)](M);return;}const I=M[l(0x166)],c=M[l(0x178)][l(0x157)]((E,p)=>E[l(0x1a8)]===I?-0x1:p['name']===I?0x1:0x0)[l(0x1b1)](E=>{const f=l,p=I===E['name']?f(0x135):'';return{'Name':''+E[f(0x1a8)]+p,'Host':E[f(0x175)],'Default\x20Project':E['project']||'-','Default\x20Service':E[f(0x124)]||'-'};});(0x0,console_format_helpers_1['printAsTable'])(c,l(0x17a));})),H=(0x0,utils_1['getCommand'])();H[D(0x1a8)](D(0x142))[D(0x156)]('Switch\x20between\x20your\x20local\x20contexts')[D(0x196)]('-n,\x20--name\x20[NAME]',D(0x1bc))[D(0x122)](V=>__awaiter(this,void 0x0,void 0x0,function*(){const a=D,M=(V===null||V===void 0x0?void 0x0:V[a(0x1a8)])||(yield this['askForContext'](a(0x142)));yield this[a(0x169)][a(0x11c)][a(0x15b)](M),(0x0,utils_1[a(0x134)])(a(0x16e)+M);}));const o=D(0x132),s=(0x0,utils_1[D(0x152)])()[D(0x1a8)](D(0x130))[D(0x156)](D(0x131))[D(0x196)](o,D(0x1b9))['action'](V=>__awaiter(this,void 0x0,void 0x0,function*(){const v=D,M=(V===null||V===void 0x0?void 0x0:V['id'])||(yield g['askForProject']());yield this[v(0x169)]['contextProvider'][v(0x161)](M),console[v(0x167)](v(0x17e),M);})),R=(0x0,utils_1['getCommand'])()[D(0x1a8)](D(0x124))[D(0x156)](D(0x173))[D(0x196)](o,D(0x19d))[D(0x122)](V=>__awaiter(this,void 0x0,void 0x0,function*(){const L=D,M=(V===null||V===void 0x0?void 0x0:V['id'])||(yield g[L(0x1b2)](this[L(0x146)]())());console['log'](L(0x189),M),yield this['apiClient']['contextProvider'][L(0x151)](M);})),y=(0x0,utils_1[D(0x152)])()[D(0x1a8)](D(0x1a0))[D(0x156)](D(0x176))['option'](o,D(0x168))[D(0x122)](V=>__awaiter(this,void 0x0,void 0x0,function*(){const X=D,M=(V===null||V===void 0x0?void 0x0:V['id'])||(yield g[X(0x190)](this[X(0x146)]())());console[X(0x167)](X(0x148),M),yield this[X(0x169)][X(0x11c)][X(0x123)](M);}));H[D(0x194)](s),H[D(0x194)](y),H[D(0x194)](R);const W=(0x0,utils_1['getCommand'])()[D(0x1a8)](D(0x1ae))['alias'](D(0x18e))['alias']('rm')[D(0x156)](D(0x172))[D(0x196)](o,D(0x127))[D(0x122)](V=>__awaiter(this,void 0x0,void 0x0,function*(){const e=D;var M;const I=(V===null||V===void 0x0?void 0x0:V['id'])||(yield this[e(0x14a)](e(0x1ae))),c=(M=this[e(0x169)][e(0x11c)][e(0x15e)]())===null||M===void 0x0?void 0x0:M[e(0x1a8)];yield this['apiClient'][e(0x11c)][e(0x140)](I),(0x0,utils_1[e(0x134)])('Local\x20context\x20\x27'+I+'\x27\x20successfully\x20removed.');if(!this[e(0x1b6)]()){(0x0,utils_1[e(0x193)])(e(0x191));return;}if(c===I){const E=(V===null||V===void 0x0?void 0x0:V[e(0x1a8)])||(yield this[e(0x14a)](e(0x16a)));yield this[e(0x169)]['contextProvider'][e(0x15b)](E),(0x0,utils_1[e(0x134)])(e(0x16e)+E);}})),B=(0x0,utils_1['getCommand'])()['name']('update-token')[D(0x12f)](D(0x19e))[D(0x156)](D(0x1ad))[D(0x196)]('-t,\x20--token\x20[TOKEN]',D(0x15f))['action'](V=>__awaiter(this,void 0x0,void 0x0,function*(){const U=D,{contextProvider:M}=this['apiClient'],I=(V===null||V===void 0x0?void 0x0:V[U(0x137)])||(yield g[U(0x13c)]()),c=M['getCurrentToken']();yield M[U(0x1a5)](I);if(yield this[U(0x1b0)]())(0x0,utils_1[U(0x134)])('Token\x20for\x20current\x20context\x20\x27'+M[U(0x17c)]()+'\x27\x20successfully\x20updated.');else{if(c)yield M[U(0x1a5)](c);(0x0,utils_1['error'])(U(0x1ba));}}));this[D(0x178)][D(0x194)](N),this[D(0x178)][D(0x194)](H),this[D(0x178)][D(0x194)](W),this[D(0x178)][D(0x194)](B);}[a2P(0x197)](Z,K){var O,g,N,H;return __awaiter(this,void 0x0,void 0x0,function*(){const i=a2K,o=!Z[i(0x179)],s=(O=Z[i(0x175)])!==null&&O!==void 0x0?O:this[i(0x125)],R=new browser_login_1['NorthflankApiBrowserLogin'](s,o,this[i(0x18a)]);let y;R['on'](i(0x147),({url:M})=>{const z=i;if(o){const I=M['replace'](/sessionToken=.*/,z(0x155));console[z(0x167)](z(0x164)+I+')'),y=inquirer[z(0x158)]([{'type':'confirm','name':'fullUrl','message':'Display\x20full\x20URL\x20to\x20allow\x20opening\x20the\x20link\x20manually','default':![]}]),y[z(0x15c)](c=>{const j=z;process['stdout'][j(0x13d)](0x0,-0x1),process[j(0x18c)][j(0x1b3)](0x1),c['fullUrl']&&console[j(0x167)](j(0x154)+M+'\x20');});}else console['log']('Open\x20this\x20URL\x20in\x20your\x20browser\x20and\x20follow\x20the\x20steps:\x0a\x09'+M+'\x20');});const {token:W,contextName:B}=yield R[i(0x19a)]()['catch'](M=>__awaiter(this,void 0x0,void 0x0,function*(){const G=i;(0x0,utils_1[G(0x11f)])('Error\x20occured\x20during\x20browser\x20login:\x20'+M[G(0x149)]+G(0x198));const I=yield this[G(0x145)](Z,K);return{'token':I[G(0x137)],'contextName':I[G(0x1a8)]};}))[i(0x126)](()=>{if(y)y['ui']['close']();}),V=(N=(g=Z['name'])!==null&&g!==void 0x0?g:B)!==null&&N!==void 0x0?N:i(0x16d)+new Date()[i(0x15a)]();return{'name':V,'token':W,'host':s,'override':(H=Z[i(0x186)])!==null&&H!==void 0x0?H:![]};});}[a2P(0x145)](Z,K){return __awaiter(this,void 0x0,void 0x0,function*(){const w=a2K,O=this['apiClient'][w(0x11c)][w(0x185)]()['contexts'],{name:g,token:N,host:H,override:o}=yield K[w(0x163)](Z,O);return{'name':g,'token':N,'host':H,'override':o};});}['getProjectName'](){const Q=a2P,Z=this[Q(0x169)][Q(0x11c)]['getCurrentProjectName']();if(Z===undefined)throw new Error(Q(0x1ac));return Z;}[a2P(0x14a)](Z){return __awaiter(this,void 0x0,void 0x0,function*(){const u=a2K;if(!this['contextAvailable']())throw new Error(u(0x13e));const K=this[u(0x169)]['contextProvider'][u(0x185)]()['contexts'][u(0x1b1)](g=>g[u(0x1a8)]),O=K[u(0x16c)]>0x4?u(0x12b):u(0x12a);return(yield inquirer[u(0x158)]([{'type':O,'name':u(0x1a8),'message':'Choose\x20the\x20context\x20to\x20'+Z+':','choices':K}]))['name'];});}[a2P(0x1b6)](){const F=a2P;return this[F(0x169)][F(0x11c)]['loadContextWrapper']()[F(0x178)][F(0x16c)]>0x0;}[a2P(0x1b0)](){return __awaiter(this,void 0x0,void 0x0,function*(){const A=a2K;try{const Z=this[A(0x169)][A(0x11c)][A(0x13a)](),K=this[A(0x169)][A(0x11c)]['getCurrentToken'](),O=Z+A(0x195),g={'Authorization':A(0x1bd)+K},N=new proxy_agent_1[(A(0x12e))](),H=yield(0x0,utils_1['retry'])(0x3)(()=>__awaiter(this,void 0x0,void 0x0,function*(){const h=A;return(0x0,node_fetch_1['default'])(O,{'method':h(0x1a4),'signal':AbortSignal[h(0x19f)](0xbb8),'headers':g,'agent':N});}));if(H['ok'])return!![];return![];}catch(o){return![];}});}}exports[a2P(0x11e)]=CliContext;