@northflank/cli 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/api-helpers.js +187 -1
- package/dist/cli.js +499 -1
- package/dist/command-overview.js +93 -1
- package/dist/console-format-helpers.js +104 -1
- package/dist/context/contextCommands.js +413 -1
- package/dist/defaults.js +6157 -1
- package/dist/inquirer-helper.js +832 -1
- package/dist/port-forward/index.js +269 -1
- package/dist/utils.js +201 -1
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,500 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
'use strict';var a1V=['status','__importStar','safeLoad','value','167juamtq','endsWith','./console-format-helpers','validate','set','523296utlTBz','parse','Failed\x20to\x20validate\x20input\x20(schema\x20mismatch):\x0a','argv',',\x20NF\x20error\x20id:\x20','=>\x20running\x20command\x20with:\x20','getCurrentProjectName','quiet','Failed\x20to\x20validate\x20input\x20(incorrect\x20format):\x20','plans','required','request','../package.json','credential','should\x20match\x20exactly\x20one\x20schema\x20in\x20oneOf','askForProject','base','regions','serviceId','askForAddon','force','isString','json','resource','label','output','VERBOSE:\x20Using\x20endpoint\x20->\x20','defineProperty','name','safeDump','projects','353620sVYWSD','ApiEndpoint','northflank','defaults','11vIwmYQ','subdomainId','get','toString','push','getCommand','19973MejVDY','CliContext','askForSubdomain','setPathVars','details','type','InquirerHelper','message','askForJob','jobId','./utils','throw','sort','action','chalk','log','option','__generator','__awaiter','ApiClientFileContextProvider','printAsTable','portFwdCmd','addonId','getCurrentServiceName','description','exitCode','\x20properties','function','retrievePayloadViaInteractiveCli','--verbose','File\x20to\x20load\x20resource\x20json\x20from','.yaml','projectId','pln','adn','default','query','call','prototype','method','schema','return','error','keys','done','586021gRfyxT','readFileSync','prj','Get\x20information\x20about\x20Northflank\x20','bind','domainId','deleteWarningPrompt','delete','144583FRgAxq','parseAsync','./inquirer-helper','forEach','askForDomain','Print\x20the\x20current\x20version\x20of\x20the\x20Northflank\x20cli','contextProvider','./port-forward','\x0a\x09details\x20:','-f,\x20--file\x20<file-path>','version','credentialId','existsSync','has','create','path','Northflank\x20cli\x20version:\x20','sent','join','addCommand','__importDefault','cred','contexts','domain','next','green','file','asyncSequential','API\x20request\x20failed\x0a\x09Message:\x20','dmn','propToType','kebabCase','Error\x20occured\x20while\x20trying\x20to\x20run\x20command,\x20error:\x20','./command-overview','pop','verbose','Unknown\x20input\x20format.\x20Not\x20valid\x20json\x20and\x20not\x20valid\x20yaml.','ops','underline','stringify','opt','JSON-formatted\x20resource\x20definition,\x20takes\x20precedence\x20over\x20\x22--file\x22','replace','getCommandOverview','find','trys','148875eQpIpk','consoleFormat','domains','3155eQelcS','3lAemeK','Command','login','OPTIONAL:\x20','backupId','askForCredentials','hasOwnProperty','map','list','addons','1pKuBbH','isArray','yml','__esModule','lodash','body','subdomain','jobs','startsWith','alias','includes','askForService','data','length','\x20--','toUpperCase','secretId','errors','__createBinding','ApiClient','endpoints','toLowerCase','getOwnPropertyNames','filter','File\x20does\x20not\x20exist:\x20','.json'];var a1V2=a1z;(function(V,z){var V1=a1z;while(!![]){try{var H=parseInt(V1(0xd6))*parseInt(V1(0xad))+parseInt(V1(0x104))*parseInt(V1(0xfe))+-parseInt(V1(0xaa))*-parseInt(V1(0xae))+-parseInt(V1(0xdb))+parseInt(V1(0x139))*-parseInt(V1(0xb8))+parseInt(V1(0xfa))+-parseInt(V1(0x131));if(H===z)break;else V['push'](V['shift']());}catch(Q){V['push'](V['shift']());}}}(a1V,0x47845));var __createBinding=this&&this[a1V2(0xca)]||(Object[a1V2(0x147)]?function(V,z,H,Q){var V3=a1V2;if(Q===undefined)Q=H;Object[V3(0xf6)](V,Q,{'enumerable':!![],'get':function(){return z[H];}});}:function(V,z,H,Q){if(Q===undefined)Q=H;V[Q]=z[H];}),__setModuleDefault=this&&this['__setModuleDefault']||(Object[a1V2(0x147)]?function(V,z){Object['defineProperty'](V,'default',{'enumerable':!![],'value':z});}:function(V,z){var V4=a1V2;V[V4(0x127)]=z;}),__importStar=this&&this[a1V2(0xd3)]||function(V){var V5=a1V2;if(V&&V[V5(0xbb)])return V;var z={};if(V!=null){for(var H in V)if(H!=='default'&&Object[V5(0x12a)][V5(0xb4)][V5(0x129)](V,H))__createBinding(z,V,H);}return __setModuleDefault(z,V),z;},__awaiter=this&&this[a1V2(0x116)]||function(V,z,H,Q){function N(A){return A instanceof H?A:new H(function(t){t(A);});}return new(H||(H=Promise))(function(A,t){var V9=a1z;function x(L){var V6=a1z;try{d(Q[V6(0x151)](L));}catch(Y){t(Y);}}function k(L){var V7=a1z;try{d(Q[V7(0x10f)](L));}catch(Y){t(Y);}}function d(L){var V8=a1z;L[V8(0x130)]?A(L[V8(0xd5)]):N(L[V8(0xd5)])['then'](x,k);}d((Q=Q['apply'](V,z||[]))[V9(0x151)]());});},__generator=this&&this[a1V2(0x115)]||function(V,z){var VV=a1V2,H={'label':0x0,'sent':function(){if(A[0x0]&0x1)throw A[0x1];return A[0x1];},'trys':[],'ops':[]},Q,N,A,x;return x={'next':k(0x0),'throw':k(0x1),'return':k(0x2)},typeof Symbol===VV(0x11f)&&(x[Symbol['iterator']]=function(){return this;}),x;function k(L){return function(Y){return d([L,Y]);};}function d(L){var Vz=VV;if(Q)throw new TypeError('Generator\x20is\x20already\x20executing.');while(H)try{if(Q=0x1,N&&(A=L[0x0]&0x2?N['return']:L[0x0]?N[Vz(0x10f)]||((A=N[Vz(0x12d)])&&A[Vz(0x129)](N),0x0):N['next'])&&!(A=A[Vz(0x129)](N,L[0x1]))[Vz(0x130)])return A;if(N=0x0,A)L=[L[0x0]&0x2,A[Vz(0xd5)]];switch(L[0x0]){case 0x0:case 0x1:A=L;break;case 0x4:H['label']++;return{'value':L[0x1],'done':![]};case 0x5:H[Vz(0xf3)]++,N=L[0x1],L=[0x0];continue;case 0x7:L=H[Vz(0xa1)][Vz(0x9e)](),H['trys'][Vz(0x9e)]();continue;default:if(!(A=H[Vz(0xa9)],A=A[Vz(0xc5)]>0x0&&A[A[Vz(0xc5)]-0x1])&&(L[0x0]===0x6||L[0x0]===0x2)){H=0x0;continue;}if(L[0x0]===0x3&&(!A||L[0x1]>A[0x0]&&L[0x1]<A[0x3])){H[Vz(0xf3)]=L[0x1];break;}if(L[0x0]===0x6&&H[Vz(0xf3)]<A[0x1]){H[Vz(0xf3)]=A[0x1],A=L;break;}if(A&&H['label']<A[0x2]){H['label']=A[0x2],H['ops'][Vz(0x102)](L);break;}if(A[0x2])H['ops'][Vz(0x9e)]();H[Vz(0xa9)][Vz(0x9e)]();continue;}L=z[Vz(0x129)](V,H);}catch(Y){L=[0x6,Y],N=0x0;}finally{Q=A=0x0;}if(L[0x0]&0x5)throw L[0x1];return{'value':L[0x0]?L[0x1]:void 0x0,'done':!![]};}},__importDefault=this&&this[a1V2(0x14d)]||function(V){var VH=a1V2;return V&&V[VH(0xbb)]?V:{'default':V};};function a1z(V,z){V=V-0x9d;var H=a1V[V];return H;}Object['defineProperty'](exports,a1V2(0xbb),{'value':!![]});var js_client_1=require('@northflank/js-client'),commander_1=__importDefault(require('commander')),fs_1=__importDefault(require('fs')),ajv_1=__importDefault(require('ajv')),chalk_1=__importDefault(require(a1V2(0x112))),_=__importStar(require(a1V2(0xbc))),contextCommands_1=require('./context/contextCommands'),utils_1=require(a1V2(0x10e)),defaults=__importStar(require('./defaults')),inquirer_helper_1=require(a1V2(0x13b)),console_format_helpers_1=require(a1V2(0xd8)),command_overview_1=require(a1V2(0x9d)),port_forward_1=require(a1V2(0x140)),yaml=require('js-yaml'),pgk=require(a1V2(0xe7));(function(){return __awaiter(void 0x0,void 0x0,void 0x0,function(){var V,z,H,Q,N,A;return __generator(this,function(t){var VQ=a1z;switch(t[VQ(0xf3)]){case 0x0:t['trys']['push']([0x0,0x3,,0x4]),V=new commander_1[(VQ(0x127))][(VQ(0xaf))](VQ(0xfc)),V[VQ(0x143)](VQ(0x149)+chalk_1[VQ(0x127)][VQ(0xa2)](pgk[VQ(0x143)]),'-v,\x20--version',VQ(0x13e)),z=new js_client_1[(VQ(0x117))]();return[0x4,(0x0,utils_1['checkUpdate'])(z)];case 0x1:t[VQ(0x14a)](),H=new js_client_1[(VQ(0xcb))](z,{'throwErrorOnHttpErrorCode':![],'customUserAgent':utils_1['customUserAgent']}),Q=new contextCommands_1[(VQ(0x105))](H),N=new port_forward_1['CliPortForward'](z),V['addCommand'](N[VQ(0x119)]),V['addCommand'](Q[VQ(0xb0)]),V[VQ(0x14c)](Q[VQ(0x14f)]),generateCommands(H,H[VQ(0xcc)],V),V[VQ(0x14c)]((0x0,command_overview_1[VQ(0xa7)])(V));return[0x4,V[VQ(0x13a)](process[VQ(0xde)])];case 0x2:t[VQ(0x14a)]();return[0x3,0x4];case 0x3:A=t[VQ(0x14a)](),(0x0,utils_1[VQ(0x12e)])(VQ(0x159)+A[VQ(0x10b)]);process[VQ(0xde)][VQ(0xa8)](function(x){var VN=VQ;return x===VN(0x121);})&&console[VQ(0x113)](A);process[VQ(0x11d)]=0x1;return[0x3,0x4];case 0x4:return[0x2];}});});}());function generateCommands(V,z,H,Q,N){var VA=a1V2,A=this;Q===void 0x0&&(Q=defaults[VA(0xfd)]);N===void 0x0&&(N=[]);var t=new inquirer_helper_1[(VA(0x10a))](new js_client_1[(VA(0xcb))](V[VA(0x13f)],{'throwErrorOnHttpErrorCode':!![],'customUserAgent':utils_1['customUserAgent']}));function x(Y,m){var Vt=VA;return Y[Vt(0xe5)]!==![]&&m===undefined;}function k(Y,m){var Vx=VA,v=Y[Vx(0xa4)],B=Y[Vx(0xf7)],l=v['default'],F=x(v,l),X=function(n){return n['length']>0x1?'--'+n:'-'+n;},h=v===null||v===void 0x0?void 0x0:v[Vx(0xc1)],b=h?_[Vx(0xb9)](h)?'-'+(h===null||h===void 0x0?void 0x0:h[Vx(0xb5)](function(n){return X(n);})['join'](',\x20-'))+',':''+X(h):'',r=F?'':Vx(0xb1),P=typeof v[Vx(0x109)]==='boolean'?b+'\x20--'+B:b+Vx(0xc6)+B+'\x20<'+B[Vx(0xc7)]()+'>';m[Vx(0x114)](P,r+v[Vx(0x11c)],l);}return Object[VA(0xce)](z)['forEach'](function(Y){var VX=VA,m,v,B,l,F=z[Y],X=Q[Y],h=N['concat']([Y]);function b(S,M){var Vk=a1z,W=Object[Vk(0xce)](S||{});W[Vk(0xb5)](function(f){return{'name':f,'opt':S[f]};})[Vk(0x110)](function(f,K){var Vd=Vk;return!x(f[Vd(0xa4)])?!x(K[Vd(0xa4)])?0x0:0x1:-0x1;})[Vk(0x13c)](function(f){k(f,M);});}function r(S,M){var VL=a1z,W={'project':[VL(0xf9),VL(0x133)],'service':['services','svc'],'credentials':[VL(0xe8),VL(0x14e)],'addon':[VL(0xb7),VL(0x126)],'job':[VL(0xbf)],'plan':[VL(0xe4),VL(0x125)],'region':[VL(0xec),'rgn'],'domain':[VL(0xac),VL(0x156)],'secret':['secrets','scr']};if(W[M])W[M][VL(0x13c)](function(f){var VY=VL;return S[VY(0xc1)](f);});}function P(S){return __awaiter(this,void 0x0,void 0x0,function(){function M(u,Z,i){var o,T;return __awaiter(this,void 0x0,void 0x0,function(){var e,C,y;return __generator(this,function(D){var Vm=a1z;switch(D[Vm(0xf3)]){case 0x0:if(!_[Vm(0x146)]((T=(o=X['opt'])===null||o===void 0x0?void 0x0:o[Vm(0x148)])!==null&&T!==void 0x0?T:{},u))return[0x3,0x3];e=!a&&!K&&i?i():undefined,y=S[u]||e;if(y)return[0x3,0x2];return[0x4,Z()];case 0x1:y=D[Vm(0x14a)](),D['label']=0x2;case 0x2:C=y,_['set'](W,u,C),D['label']=0x3;case 0x3:return[0x2];}});});}var W,f,K,a,R;return __generator(this,function(u){var Vv=a1z;switch(u[Vv(0xf3)]){case 0x0:W={},f=V[Vv(0x13f)],K=h[Vv(0xc2)](Vv(0x138)),a=S['noDefaults']===!![];return[0x4,M(Vv(0x124),t[Vv(0xea)][Vv(0x135)](t),f[Vv(0xe1)][Vv(0x135)](f))];case 0x1:u[Vv(0x14a)](),R=W===null||W===void 0x0?void 0x0:W['projectId'];return[0x4,M(Vv(0xed),t[Vv(0xc3)](R)['bind'](t),f[Vv(0x11b)][Vv(0x135)](f))];case 0x2:u['sent']();return[0x4,M(Vv(0x11a),t[Vv(0xee)](R)[Vv(0x135)](t))];case 0x3:u[Vv(0x14a)]();return[0x4,M(Vv(0x10d),t[Vv(0x10c)](R)['bind'](t),f['getCurrentJobName'][Vv(0x135)](f))];case 0x4:u[Vv(0x14a)]();return[0x4,M('runId',t['askForJobRun'](W[Vv(0x10d)],R)['bind'](t))];case 0x5:u[Vv(0x14a)]();return[0x4,M(Vv(0xc8),t['askForSecret'](R)[Vv(0x135)](t))];case 0x6:u[Vv(0x14a)]();return[0x4,M(Vv(0x150),t[Vv(0x13d)]['bind'](t))];case 0x7:u['sent']();return[0x4,M(Vv(0x136),t[Vv(0x13d)][Vv(0x135)](t))];case 0x8:u['sent']();return[0x4,M(Vv(0x144),t[Vv(0xb3)]['bind'](t))];case 0x9:u[Vv(0x14a)]();return[0x4,M(Vv(0xbe),t[Vv(0x106)](W[Vv(0x150)])[Vv(0x135)](t))];case 0xa:u[Vv(0x14a)]();return[0x4,M(Vv(0xff),t[Vv(0x106)](W[Vv(0x136)])[Vv(0x135)](t))];case 0xb:u['sent']();return[0x4,M(Vv(0xb2),t['askForAddonBackup'](R,W['addonId'])[Vv(0x135)](t))];case 0xc:u[Vv(0x14a)]();return[0x2,W];}});});}function n(S){var M,W;return __awaiter(this,void 0x0,void 0x0,function(){var f,K,a=this;return __generator(this,function(R){var VB=a1z;switch(R[VB(0xf3)]){case 0x0:f={},K=Object[VB(0x12f)]((W=(M=X[VB(0xa4)])===null||M===void 0x0?void 0x0:M[VB(0x128)])!==null&&W!==void 0x0?W:{});return[0x4,(0x0,utils_1[VB(0x154)])(K,function(u){return __awaiter(a,void 0x0,void 0x0,function(){var Z;return __generator(this,function(i){var Vl=a1z;switch(i[Vl(0xf3)]){case 0x0:Z={};return[0x4,t[Vl(0x157)]([''+u],X[Vl(0xa4)][Vl(0x128)][u][Vl(0x12c)],Z)];case 0x1:i[Vl(0x14a)](),_[Vl(0xda)](f,u,Z[u]);return[0x2,Z];}});});})];case 0x1:R[VB(0x14a)]();return[0x2,f];}});});}function g(){var VF=a1z;switch(h[0x0]){case VF(0x100):return VF(0x134)+(h[0x1]||VF(0xf2))+'s';case'update':return'Update\x20Northflank\x20'+(h[0x1]||VF(0xf2))+VF(0x11e);default:return _['upperFirst'](Y)+'\x20Northflank\x20resources';}}if(!(F instanceof js_client_1[VX(0xfb)])){var j=(0x0,utils_1[VX(0x103)])()[VX(0xf7)](_[VX(0x158)](Y))[VX(0x11c)](g());r(j,Y),H['addCommand'](j),generateCommands(V,F,j,X,h);}else{var E=F,q=(0x0,utils_1[VX(0x103)])(!![])[VX(0xf7)](_[VX(0x158)](Y))['description'](E[VX(0x11c)]||'');r(q,Y),((m=X[VX(0xa4)])===null||m===void 0x0?void 0x0:m[VX(0xbd)])&&(q[VX(0x114)](VX(0x142),VX(0x122)),q[VX(0x114)]('-i,\x20--input\x20<resource-def>',VX(0xa5))),b((v=X[VX(0xa4)])===null||v===void 0x0?void 0x0:v['path'],q),b((B=X['opt'])===null||B===void 0x0?void 0x0:B[VX(0x128)],q),b((l=X[VX(0xa4)])===null||l===void 0x0?void 0x0:l[VX(0xeb)],q),q[VX(0x111)](function(S){return __awaiter(A,void 0x0,void 0x0,function(){var M,W,f,K,a,R,u,Z,i,o,T,e,C,y,D,U,p,O,s,w,G,c,J;return __generator(this,function(I){var Vh=a1z;switch(I[Vh(0xf3)]){case 0x0:return[0x4,P(S)];case 0x1:M=I[Vh(0x14a)](),t[Vh(0x107)](M);return[0x4,n(S)];case 0x2:W=I[Vh(0x14a)](),f=Object[Vh(0x12f)]((c=(G=X[Vh(0xa4)])===null||G===void 0x0?void 0x0:G[Vh(0x148)])!==null&&c!==void 0x0?c:{})[Vh(0xb5)](function(V0){var Vb=Vh;return V0+'='+chalk_1[Vb(0x127)][Vb(0x152)](M[V0]);})[Vh(0x14b)](',\x20');f[Vh(0xc5)]>0x0&&(K=Vh(0xe0)+f,console['log'](K));if(!((J=X[Vh(0xa4)])===null||J===void 0x0?void 0x0:J[Vh(0xbd)]))return[0x3,0x4];return[0x4,L(S,X,h)];case 0x3:R=I[Vh(0x14a)]();return[0x3,0x5];case 0x4:R=undefined,I['label']=0x5;case 0x5:a=R,u=!S[Vh(0xef)]&&h['includes'](Vh(0x138));if(!u)return[0x3,0x7];return[0x4,t[Vh(0x137)]()];case 0x6:u=!I['sent'](),I[Vh(0xf3)]=0x7;case 0x7:if(u)return(0x0,utils_1['warning'])('Resource\x20was\x20not\x20deleted.'),[0x2];return[0x4,F[Vh(0x129)]({'parameters':M,'options':W,'data':a})];case 0x8:Z=I['sent'](),i=Z[Vh(0xc4)],o=Z[Vh(0xe6)],T=Z[Vh(0x12e)];(S===null||S===void 0x0?void 0x0:S[Vh(0x9f)])&&(console[Vh(0x113)](Vh(0xf5)+o[Vh(0x12b)]+':'+o['url']),console[Vh(0x113)]('VERBOSE:\x20Request\x20body\x20->\x20'+o[Vh(0xbd)]));if(T){e=T[Vh(0x108)]?Vh(0x141)+JSON[Vh(0xa3)](T[Vh(0x108)]):'',C=(T===null||T===void 0x0?void 0x0:T['id'])?Vh(0xdf)+T['id']:'',y='(HTTP\x20status\x20code:\x20'+T[Vh(0xd2)]+C+')';throw new Error(Vh(0x155)+T['message']+'\x20'+y+e);}if(!(S===null||S===void 0x0?void 0x0:S[Vh(0xe2)])){D=S===null||S===void 0x0?void 0x0:S[Vh(0xf4)];if(D===Vh(0xf1))console['log']((0x0,console_format_helpers_1[Vh(0xab)])(i));else{if(D==='yaml'||D===Vh(0xba))console[Vh(0x113)](yaml[Vh(0xf8)](i));else h[Vh(0xa8)](function(V0){var Vr=Vh;return V0===Vr(0xb6);})?(U=(D===null||D===void 0x0?void 0x0:D[Vh(0xc0)]('custom-columns='))?D[Vh(0xa6)]('custom-columns=','')['split'](',')[Vh(0xb5)](function(V0){var VP=Vh;return V0[VP(0xcd)]();}):undefined,p=h[h[Vh(0xc5)]-0x1],O=''+p+(p['endsWith']('s')?'':'s'),s=_['upperFirst'](O),w=_['has'](i,O)?i[O]:i,(0x0,console_format_helpers_1[Vh(0x118)])(w,s,U)):console[Vh(0x113)]((0x0,console_format_helpers_1[Vh(0xab)])(i));}}return[0x2];}});});}),H['addCommand'](q);}});function d(Y,m,v){return __awaiter(this,void 0x0,void 0x0,function(){var B,l,F,X;return __generator(this,function(h){var Vn=a1z;switch(h[Vn(0xf3)]){case 0x0:B=Y['input'],l=Y[Vn(0x153)];if(B!==undefined)try{return[0x2,JSON[Vn(0xdc)](B)];}catch(b){try{return[0x2,yaml[Vn(0xd4)](B)];}catch(r){throw new Error(Vn(0xa0));}}if(l!==undefined){if(!fs_1['default'][Vn(0x145)](l))throw new Error(Vn(0xd0)+l);F=fs_1[Vn(0x127)][Vn(0x132)](l)[Vn(0x101)](),X=void 0x0;try{if(_[Vn(0xf0)](F)){if(Y[Vn(0x153)][Vn(0xd7)](Vn(0xd1)))X=JSON[Vn(0xdc)](F);else{if(Y[Vn(0x153)][Vn(0xd7)](Vn(0x123))||Y[Vn(0x153)]['endsWith'](Vn(0xba)))X=yaml['safeLoad'](F);else throw new Error('Unknown\x20input\x20file\x20type:\x20'+Y['file']['split']('.')[Vn(0x9e)]());}}else X=F;return[0x2,X];}catch(P){throw new Error(Vn(0xe3)+P[Vn(0x10b)]);}}return[0x4,t[Vn(0x120)](m,{'cmdPath':v})];case 0x1:return[0x2,h[Vn(0x14a)]()];}});});}function L(Y,m,v){var B;return __awaiter(this,void 0x0,void 0x0,function(){var l,F,X,h;return __generator(this,function(b){var Vg=a1z;switch(b[Vg(0xf3)]){case 0x0:return[0x4,d(Y,m,v)];case 0x1:l=b[Vg(0x14a)](),F=new ajv_1[(Vg(0x127))]({'allErrors':!![]}),X=F[Vg(0xd9)](m[Vg(0xa4)]['body'],l),h=(B=F===null||F===void 0x0?void 0x0:F['errors'])===null||B===void 0x0?void 0x0:B[Vg(0xcf)](function(r){var Vj=Vg,P;return!((P=r===null||r===void 0x0?void 0x0:r['message'])===null||P===void 0x0?void 0x0:P[Vj(0xc2)](Vj(0xe9)));});if(!X&&h!==undefined&&(h===null||h===void 0x0?void 0x0:h['length'])>0x0)throw new Error(Vg(0xdd)+JSON[Vg(0xa3)](F[Vg(0xc9)],null,'\x20'));return[0x2,l];}});});}}
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
6
|
+
}) : (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
o[k2] = m[k];
|
|
9
|
+
}));
|
|
10
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
11
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12
|
+
}) : function(o, v) {
|
|
13
|
+
o["default"] = v;
|
|
14
|
+
});
|
|
15
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
16
|
+
if (mod && mod.__esModule) return mod;
|
|
17
|
+
var result = {};
|
|
18
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
19
|
+
__setModuleDefault(result, mod);
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
23
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
24
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
26
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
27
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
28
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
32
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
33
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
34
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
35
|
+
function step(op) {
|
|
36
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
37
|
+
while (_) try {
|
|
38
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
39
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
40
|
+
switch (op[0]) {
|
|
41
|
+
case 0: case 1: t = op; break;
|
|
42
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
43
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
44
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
45
|
+
default:
|
|
46
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
47
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
48
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
49
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
50
|
+
if (t[2]) _.ops.pop();
|
|
51
|
+
_.trys.pop(); continue;
|
|
52
|
+
}
|
|
53
|
+
op = body.call(thisArg, _);
|
|
54
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
55
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
59
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
|
+
};
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
var js_client_1 = require("@northflank/js-client");
|
|
63
|
+
var commander_1 = __importDefault(require("commander"));
|
|
64
|
+
var fs_1 = __importDefault(require("fs"));
|
|
65
|
+
var ajv_1 = __importDefault(require("ajv"));
|
|
66
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
67
|
+
var _ = __importStar(require("lodash"));
|
|
68
|
+
var contextCommands_1 = require("./context/contextCommands");
|
|
69
|
+
var utils_1 = require("./utils");
|
|
70
|
+
var defaults = __importStar(require("./defaults"));
|
|
71
|
+
var inquirer_helper_1 = require("./inquirer-helper");
|
|
72
|
+
var console_format_helpers_1 = require("./console-format-helpers");
|
|
73
|
+
var command_overview_1 = require("./command-overview");
|
|
74
|
+
var port_forward_1 = require("./port-forward");
|
|
75
|
+
var yaml = require('js-yaml');
|
|
76
|
+
var pgk = require('../package.json');
|
|
77
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
78
|
+
var program, contextProvider, apiClient, contextCmds, portForwardCmds, e_1;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
_a.trys.push([0, 3, , 4]);
|
|
83
|
+
program = new commander_1.default.Command('northflank');
|
|
84
|
+
program.enablePositionalOptions(true);
|
|
85
|
+
program.version("Northflank cli version: " + chalk_1.default.underline(pgk.version), '-v, --version', 'Print the current version of the Northflank cli');
|
|
86
|
+
contextProvider = new js_client_1.ApiClientFileContextProvider();
|
|
87
|
+
return [4 /*yield*/, (0, utils_1.checkUpdate)(contextProvider)];
|
|
88
|
+
case 1:
|
|
89
|
+
_a.sent();
|
|
90
|
+
apiClient = new js_client_1.ApiClient(contextProvider, {
|
|
91
|
+
throwErrorOnHttpErrorCode: false,
|
|
92
|
+
customUserAgent: utils_1.customUserAgent,
|
|
93
|
+
});
|
|
94
|
+
contextCmds = new contextCommands_1.CliContext(apiClient);
|
|
95
|
+
portForwardCmds = new port_forward_1.CliPortForward(contextProvider);
|
|
96
|
+
program.addCommand(portForwardCmds.portFwdCmd);
|
|
97
|
+
program.addCommand(contextCmds.login);
|
|
98
|
+
program.addCommand(contextCmds.contexts);
|
|
99
|
+
generateCommands(apiClient, apiClient.endpoints, program);
|
|
100
|
+
program.addCommand((0, command_overview_1.getCommandOverview)(program));
|
|
101
|
+
return [4 /*yield*/, program.parseAsync(process.argv)];
|
|
102
|
+
case 2:
|
|
103
|
+
_a.sent();
|
|
104
|
+
return [3 /*break*/, 4];
|
|
105
|
+
case 3:
|
|
106
|
+
e_1 = _a.sent();
|
|
107
|
+
(0, utils_1.error)("Error occured while trying to run command, error: " + e_1.message);
|
|
108
|
+
if (process.argv.find(function (arg) { return arg === '--verbose'; })) {
|
|
109
|
+
console.log(e_1);
|
|
110
|
+
}
|
|
111
|
+
process.exitCode = 1;
|
|
112
|
+
return [3 /*break*/, 4];
|
|
113
|
+
case 4: return [2 /*return*/];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}); })();
|
|
117
|
+
/** Automatically adds commands recursively.
|
|
118
|
+
* @param apiClient
|
|
119
|
+
* @param endpoints
|
|
120
|
+
* @param cmd Root command to add the generated commands to
|
|
121
|
+
* @param currentDefaults
|
|
122
|
+
* @param cliPath
|
|
123
|
+
*/
|
|
124
|
+
function generateCommands(apiClient, endpoints, cmd, currentDefaults, cliPath) {
|
|
125
|
+
if (currentDefaults === void 0) { currentDefaults = defaults.defaults; }
|
|
126
|
+
if (cliPath === void 0) { cliPath = []; }
|
|
127
|
+
var inquirerHelper = new inquirer_helper_1.InquirerHelper(new js_client_1.ApiClient(apiClient.contextProvider, {
|
|
128
|
+
throwErrorOnHttpErrorCode: true,
|
|
129
|
+
customUserAgent: utils_1.customUserAgent,
|
|
130
|
+
}));
|
|
131
|
+
function isRequired(opt, defaultVal) {
|
|
132
|
+
return opt.required !== false && defaultVal === undefined;
|
|
133
|
+
}
|
|
134
|
+
function parseOptions(option, leafCommand) {
|
|
135
|
+
var opt = option.opt, name = option.name;
|
|
136
|
+
var defaultVal = opt.default;
|
|
137
|
+
var required = isRequired(opt, defaultVal);
|
|
138
|
+
var toOption = function (alias) { return (alias.length > 1 ? "--" + alias : "-" + alias); };
|
|
139
|
+
var alias = opt === null || opt === void 0 ? void 0 : opt.alias;
|
|
140
|
+
// eslint-disable-next-line no-nested-ternary
|
|
141
|
+
var aliases = alias
|
|
142
|
+
? _.isArray(alias)
|
|
143
|
+
? "-" + (alias === null || alias === void 0 ? void 0 : alias.map(function (a) { return toOption(a); }).join(', -')) + ","
|
|
144
|
+
: "" + toOption(alias)
|
|
145
|
+
: '';
|
|
146
|
+
var optionalText = required ? '' : 'OPTIONAL: ';
|
|
147
|
+
var flags = typeof opt.type === 'boolean'
|
|
148
|
+
? aliases + " --" + name
|
|
149
|
+
: aliases + " --" + name + " <" + name.toUpperCase() + ">";
|
|
150
|
+
var description = optionalText + opt.description;
|
|
151
|
+
leafCommand.option(flags, description, defaultVal);
|
|
152
|
+
}
|
|
153
|
+
return Object.getOwnPropertyNames(currentDefaults).forEach(function (name) {
|
|
154
|
+
var endpoint = endpoints[name];
|
|
155
|
+
var defaultOpt = currentDefaults[name];
|
|
156
|
+
var nextCliPath = cliPath.concat([name]);
|
|
157
|
+
function parseOpts(baseOpts, leafCommand) {
|
|
158
|
+
var baseOptNames = Object.getOwnPropertyNames(baseOpts || {});
|
|
159
|
+
baseOptNames
|
|
160
|
+
.map(function (optString) {
|
|
161
|
+
return { name: optString, opt: baseOpts[optString] };
|
|
162
|
+
})
|
|
163
|
+
// eslint-disable-next-line no-nested-ternary
|
|
164
|
+
.sort(function (opt1, opt2) { return (!isRequired(opt1.opt) ? (!isRequired(opt2.opt) ? 0 : 1) : -1); })
|
|
165
|
+
.forEach(function (option) {
|
|
166
|
+
parseOptions(option, leafCommand);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function setAliases(nextCmd, cmdName) {
|
|
170
|
+
var aliases = [
|
|
171
|
+
['project', 'projects', 'prj'],
|
|
172
|
+
['service', 'services', 'svc'],
|
|
173
|
+
['credentials', 'credential', 'cred'],
|
|
174
|
+
['addon', 'addons', 'adn'],
|
|
175
|
+
['job', 'jobs'],
|
|
176
|
+
['plan', 'plans', 'pln'],
|
|
177
|
+
['region', 'regions', 'rgn'],
|
|
178
|
+
['domain', 'domains', 'dmn'],
|
|
179
|
+
['secret', 'secrets', 'scrt'],
|
|
180
|
+
];
|
|
181
|
+
var alias = aliases.find(function (a) { return a.includes(cmdName); });
|
|
182
|
+
if (alias !== undefined)
|
|
183
|
+
nextCmd.aliases(alias.filter(function (a) { return a !== cmdName; }));
|
|
184
|
+
}
|
|
185
|
+
function setPathVariables(opt) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
187
|
+
/**
|
|
188
|
+
* @param resource Resource identifier
|
|
189
|
+
* @param ctx Get result from client context
|
|
190
|
+
* @param ask Get result by asking interactively
|
|
191
|
+
*/
|
|
192
|
+
function setVar(resource, ask, ctx) {
|
|
193
|
+
var _a, _b;
|
|
194
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
195
|
+
var ctxRes, id, _c;
|
|
196
|
+
return __generator(this, function (_d) {
|
|
197
|
+
switch (_d.label) {
|
|
198
|
+
case 0:
|
|
199
|
+
if (!_.has((_b = (_a = defaultOpt.opt) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : {}, resource)) return [3 /*break*/, 3];
|
|
200
|
+
ctxRes = !askExplicitly && !isDeleteCmd && ctx ? ctx() : undefined;
|
|
201
|
+
_c = opt[resource] || // Always check command arguments first
|
|
202
|
+
ctxRes;
|
|
203
|
+
if (_c) return [3 /*break*/, 2];
|
|
204
|
+
return [4 /*yield*/, ask()];
|
|
205
|
+
case 1:
|
|
206
|
+
_c = (_d.sent());
|
|
207
|
+
_d.label = 2;
|
|
208
|
+
case 2:
|
|
209
|
+
id = _c;
|
|
210
|
+
_.set(parameters, resource, id);
|
|
211
|
+
_d.label = 3;
|
|
212
|
+
case 3: return [2 /*return*/];
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
var parameters, contextProvider, isDeleteCmd, askExplicitly, projectId;
|
|
218
|
+
return __generator(this, function (_a) {
|
|
219
|
+
switch (_a.label) {
|
|
220
|
+
case 0:
|
|
221
|
+
parameters = {};
|
|
222
|
+
contextProvider = apiClient.contextProvider;
|
|
223
|
+
isDeleteCmd = nextCliPath.includes('delete');
|
|
224
|
+
askExplicitly = opt.noDefaults === true;
|
|
225
|
+
return [4 /*yield*/, setVar('projectId', inquirerHelper.askForProject.bind(inquirerHelper), contextProvider.getCurrentProjectName.bind(contextProvider))];
|
|
226
|
+
case 1:
|
|
227
|
+
_a.sent();
|
|
228
|
+
projectId = parameters === null || parameters === void 0 ? void 0 : parameters.projectId;
|
|
229
|
+
return [4 /*yield*/, setVar('serviceId', inquirerHelper.askForService(projectId).bind(inquirerHelper), contextProvider.getCurrentServiceName.bind(contextProvider))];
|
|
230
|
+
case 2:
|
|
231
|
+
_a.sent();
|
|
232
|
+
return [4 /*yield*/, setVar('addonId', inquirerHelper.askForAddon(projectId).bind(inquirerHelper))];
|
|
233
|
+
case 3:
|
|
234
|
+
_a.sent();
|
|
235
|
+
return [4 /*yield*/, setVar('jobId', inquirerHelper.askForJob(projectId).bind(inquirerHelper), contextProvider.getCurrentJobName.bind(contextProvider))];
|
|
236
|
+
case 4:
|
|
237
|
+
_a.sent();
|
|
238
|
+
return [4 /*yield*/, setVar('runId', inquirerHelper.askForJobRun(parameters.jobId, projectId).bind(inquirerHelper))];
|
|
239
|
+
case 5:
|
|
240
|
+
_a.sent();
|
|
241
|
+
return [4 /*yield*/, setVar('secretId', inquirerHelper.askForSecret(projectId).bind(inquirerHelper))];
|
|
242
|
+
case 6:
|
|
243
|
+
_a.sent();
|
|
244
|
+
return [4 /*yield*/, setVar('domain', inquirerHelper.askForDomain.bind(inquirerHelper))];
|
|
245
|
+
case 7:
|
|
246
|
+
_a.sent();
|
|
247
|
+
return [4 /*yield*/, setVar('domainId', inquirerHelper.askForDomain.bind(inquirerHelper))];
|
|
248
|
+
case 8:
|
|
249
|
+
_a.sent();
|
|
250
|
+
return [4 /*yield*/, setVar('credentialId', inquirerHelper.askForCredentials.bind(inquirerHelper))];
|
|
251
|
+
case 9:
|
|
252
|
+
_a.sent();
|
|
253
|
+
return [4 /*yield*/, setVar('subdomain', inquirerHelper.askForSubdomain(parameters.domain).bind(inquirerHelper))];
|
|
254
|
+
case 10:
|
|
255
|
+
_a.sent();
|
|
256
|
+
return [4 /*yield*/, setVar('subdomainId', inquirerHelper.askForSubdomain(parameters.domainId).bind(inquirerHelper))];
|
|
257
|
+
case 11:
|
|
258
|
+
_a.sent();
|
|
259
|
+
return [4 /*yield*/, setVar('backupId', inquirerHelper.askForAddonBackup(projectId, parameters.addonId).bind(inquirerHelper))];
|
|
260
|
+
case 12:
|
|
261
|
+
_a.sent();
|
|
262
|
+
return [2 /*return*/, parameters];
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function setQueryVariables(opt) {
|
|
268
|
+
var _a, _b;
|
|
269
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
270
|
+
var options, queryArgs;
|
|
271
|
+
var _this = this;
|
|
272
|
+
return __generator(this, function (_c) {
|
|
273
|
+
switch (_c.label) {
|
|
274
|
+
case 0:
|
|
275
|
+
options = {};
|
|
276
|
+
queryArgs = Object.keys((_b = (_a = defaultOpt.opt) === null || _a === void 0 ? void 0 : _a.query) !== null && _b !== void 0 ? _b : {});
|
|
277
|
+
return [4 /*yield*/, (0, utils_1.asyncSequential)(queryArgs, function (key) { return __awaiter(_this, void 0, void 0, function () {
|
|
278
|
+
var result;
|
|
279
|
+
return __generator(this, function (_a) {
|
|
280
|
+
switch (_a.label) {
|
|
281
|
+
case 0:
|
|
282
|
+
result = {};
|
|
283
|
+
return [4 /*yield*/, inquirerHelper.propToType(["" + key], defaultOpt.opt.query[key].schema, result)];
|
|
284
|
+
case 1:
|
|
285
|
+
_a.sent();
|
|
286
|
+
_.set(options, key, result[key]);
|
|
287
|
+
return [2 /*return*/, result];
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}); })];
|
|
291
|
+
case 1:
|
|
292
|
+
_c.sent();
|
|
293
|
+
return [2 /*return*/, options];
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
function getDescription() {
|
|
299
|
+
switch (nextCliPath[0]) {
|
|
300
|
+
case 'get':
|
|
301
|
+
return "Get information about Northflank " + (nextCliPath[1] || 'resource') + "s";
|
|
302
|
+
case 'update':
|
|
303
|
+
return "Update Northflank " + (nextCliPath[1] || 'resource') + " properties";
|
|
304
|
+
default:
|
|
305
|
+
return _.upperFirst(name) + " Northflank resources";
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function constructCommand(currentEndpoint, isEndpointCommand) {
|
|
309
|
+
var _this = this;
|
|
310
|
+
var _a, _b, _c, _d;
|
|
311
|
+
if (!isEndpointCommand) {
|
|
312
|
+
var nextCmd = (0, utils_1.getCommand)().name(_.kebabCase(name)).description(getDescription());
|
|
313
|
+
setAliases(nextCmd, name);
|
|
314
|
+
return nextCmd;
|
|
315
|
+
}
|
|
316
|
+
var leafCommand = (0, utils_1.getCommand)(true)
|
|
317
|
+
.name(_.kebabCase(name))
|
|
318
|
+
.description(currentEndpoint.description || '');
|
|
319
|
+
setAliases(leafCommand, name);
|
|
320
|
+
if ((_a = defaultOpt.opt) === null || _a === void 0 ? void 0 : _a.body) {
|
|
321
|
+
leafCommand.option('-f, --file <file-path>', 'File to load resource json from');
|
|
322
|
+
leafCommand.option('-i, --input <resource-def>', 'JSON-formatted resource definition, takes precedence over "--file"');
|
|
323
|
+
}
|
|
324
|
+
parseOpts((_b = defaultOpt.opt) === null || _b === void 0 ? void 0 : _b.path, leafCommand);
|
|
325
|
+
parseOpts((_c = defaultOpt.opt) === null || _c === void 0 ? void 0 : _c.query, leafCommand);
|
|
326
|
+
parseOpts((_d = defaultOpt.opt) === null || _d === void 0 ? void 0 : _d.base, leafCommand);
|
|
327
|
+
leafCommand.action(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
328
|
+
var opt, parameters, options, contextIndicator, contextInfoMessage, jsonResource, _a, _b, _c, data, request, errorResponse, errorDetails, nfId, id, output, columns, resourceId, resourceDescr, title, tableData;
|
|
329
|
+
var _d, _e, _f;
|
|
330
|
+
return __generator(this, function (_g) {
|
|
331
|
+
switch (_g.label) {
|
|
332
|
+
case 0:
|
|
333
|
+
(0, utils_1.assertContextExisting)(apiClient);
|
|
334
|
+
opt = leafCommand.opts();
|
|
335
|
+
return [4 /*yield*/, setPathVariables(opt)];
|
|
336
|
+
case 1:
|
|
337
|
+
parameters = _g.sent();
|
|
338
|
+
inquirerHelper.setPathVars(parameters);
|
|
339
|
+
return [4 /*yield*/, setQueryVariables(opt)];
|
|
340
|
+
case 2:
|
|
341
|
+
options = _g.sent();
|
|
342
|
+
contextIndicator = Object.keys((_e = (_d = defaultOpt.opt) === null || _d === void 0 ? void 0 : _d.path) !== null && _e !== void 0 ? _e : {})
|
|
343
|
+
.map(function (p) { return p + "=" + chalk_1.default.green(parameters[p]); })
|
|
344
|
+
.join(', ');
|
|
345
|
+
if (contextIndicator.length > 0) {
|
|
346
|
+
contextInfoMessage = "=> running command with: " + contextIndicator;
|
|
347
|
+
console.log(contextInfoMessage);
|
|
348
|
+
}
|
|
349
|
+
if (!((_f = defaultOpt.opt) === null || _f === void 0 ? void 0 : _f.body)) return [3 /*break*/, 4];
|
|
350
|
+
return [4 /*yield*/, parsePayload(opt, defaultOpt, nextCliPath)];
|
|
351
|
+
case 3:
|
|
352
|
+
_a = _g.sent();
|
|
353
|
+
return [3 /*break*/, 5];
|
|
354
|
+
case 4:
|
|
355
|
+
_a = undefined;
|
|
356
|
+
_g.label = 5;
|
|
357
|
+
case 5:
|
|
358
|
+
jsonResource = _a;
|
|
359
|
+
_b = !opt.force &&
|
|
360
|
+
nextCliPath.includes('delete');
|
|
361
|
+
if (!_b) return [3 /*break*/, 7];
|
|
362
|
+
return [4 /*yield*/, inquirerHelper.deleteWarningPrompt()];
|
|
363
|
+
case 6:
|
|
364
|
+
_b = !(_g.sent());
|
|
365
|
+
_g.label = 7;
|
|
366
|
+
case 7:
|
|
367
|
+
if (_b) {
|
|
368
|
+
(0, utils_1.warning)('Resource was not deleted.');
|
|
369
|
+
return [2 /*return*/];
|
|
370
|
+
}
|
|
371
|
+
return [4 /*yield*/, endpoint.call({ parameters: parameters, options: options, data: jsonResource })];
|
|
372
|
+
case 8:
|
|
373
|
+
_c = _g.sent(), data = _c.data, request = _c.request, errorResponse = _c.error;
|
|
374
|
+
if (opt === null || opt === void 0 ? void 0 : opt.verbose) {
|
|
375
|
+
console.log("VERBOSE: Using endpoint -> " + request.method + ":" + request.url);
|
|
376
|
+
console.log("VERBOSE: Request body -> " + request.body);
|
|
377
|
+
}
|
|
378
|
+
if (errorResponse) {
|
|
379
|
+
errorDetails = errorResponse.details
|
|
380
|
+
? "\n\tdetails :" + JSON.stringify(errorResponse.details)
|
|
381
|
+
: '';
|
|
382
|
+
nfId = (errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.id) ? ", NF error id: " + errorResponse.id : '';
|
|
383
|
+
id = "(HTTP status code: " + errorResponse.status + nfId + ")";
|
|
384
|
+
throw new Error("API request failed\n\tMessage: " + errorResponse.message + " " + id + errorDetails);
|
|
385
|
+
}
|
|
386
|
+
if (!(opt === null || opt === void 0 ? void 0 : opt.quiet)) {
|
|
387
|
+
output = opt === null || opt === void 0 ? void 0 : opt.output;
|
|
388
|
+
if (output === 'json') {
|
|
389
|
+
console.log((0, console_format_helpers_1.consoleFormat)(data));
|
|
390
|
+
}
|
|
391
|
+
else if (output === 'yaml' || output === 'yml') {
|
|
392
|
+
console.log(yaml.safeDump(data));
|
|
393
|
+
}
|
|
394
|
+
else if (nextCliPath.find(function (p) { return p === 'list'; })) {
|
|
395
|
+
columns = (output === null || output === void 0 ? void 0 : output.startsWith('custom-columns='))
|
|
396
|
+
? output
|
|
397
|
+
.replace('custom-columns=', '')
|
|
398
|
+
.split(',')
|
|
399
|
+
.map(function (c) { return c.toLowerCase(); })
|
|
400
|
+
: undefined;
|
|
401
|
+
resourceId = nextCliPath[nextCliPath.length - 1];
|
|
402
|
+
resourceDescr = "" + resourceId + (resourceId.endsWith('s') ? '' : 's');
|
|
403
|
+
title = _.upperFirst(resourceDescr);
|
|
404
|
+
tableData = _.has(data, resourceDescr) ? data[resourceDescr] : data;
|
|
405
|
+
(0, console_format_helpers_1.printAsTable)(tableData, title, columns);
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
console.log((0, console_format_helpers_1.consoleFormat)(data));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return [2 /*return*/];
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}); });
|
|
415
|
+
return leafCommand;
|
|
416
|
+
}
|
|
417
|
+
var isEndpointCommand = _.has(defaultOpt, 'opt');
|
|
418
|
+
var currentEndpoint = endpoint;
|
|
419
|
+
var command = constructCommand(currentEndpoint, isEndpointCommand);
|
|
420
|
+
cmd.addCommand(command);
|
|
421
|
+
var optWithoutOpt = _.omit(defaultOpt, 'opt');
|
|
422
|
+
if (Object.keys(optWithoutOpt).length > 0) {
|
|
423
|
+
// If this command has more subcommands, add them recursively
|
|
424
|
+
generateCommands(apiClient, endpoint, command, optWithoutOpt, nextCliPath);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
function getInput(opt, defaultOpt, cmdPath) {
|
|
428
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
429
|
+
var input, file, fileContent, jsonResource;
|
|
430
|
+
return __generator(this, function (_a) {
|
|
431
|
+
switch (_a.label) {
|
|
432
|
+
case 0:
|
|
433
|
+
input = opt.input, file = opt.file;
|
|
434
|
+
if (input !== undefined) {
|
|
435
|
+
try {
|
|
436
|
+
return [2 /*return*/, JSON.parse(input)];
|
|
437
|
+
}
|
|
438
|
+
catch (e) {
|
|
439
|
+
try {
|
|
440
|
+
return [2 /*return*/, yaml.safeLoad(input)];
|
|
441
|
+
}
|
|
442
|
+
catch (d) {
|
|
443
|
+
throw new Error('Unknown input format. Not valid json and not valid yaml.');
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (file !== undefined) {
|
|
448
|
+
if (!fs_1.default.existsSync(file)) {
|
|
449
|
+
throw new Error("File does not exist: " + file);
|
|
450
|
+
}
|
|
451
|
+
fileContent = fs_1.default.readFileSync(file).toString();
|
|
452
|
+
jsonResource = void 0;
|
|
453
|
+
try {
|
|
454
|
+
if (_.isString(fileContent)) {
|
|
455
|
+
if (opt.file.endsWith('.json')) {
|
|
456
|
+
jsonResource = JSON.parse(fileContent);
|
|
457
|
+
}
|
|
458
|
+
else if (opt.file.endsWith('.yaml') || opt.file.endsWith('yml')) {
|
|
459
|
+
jsonResource = yaml.safeLoad(fileContent);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
throw new Error("Unknown input file type: " + opt.file.split('.').pop());
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
jsonResource = fileContent;
|
|
467
|
+
}
|
|
468
|
+
return [2 /*return*/, jsonResource];
|
|
469
|
+
}
|
|
470
|
+
catch (e) {
|
|
471
|
+
throw new Error("Failed to validate input (incorrect format): " + e.message);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return [4 /*yield*/, inquirerHelper.retrievePayloadViaInteractiveCli(defaultOpt, { cmdPath: cmdPath })];
|
|
475
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
function parsePayload(opt, defaultOpt, cmdPath) {
|
|
481
|
+
var _a;
|
|
482
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
483
|
+
var bodyObject, ajv, valid, filteredErrors;
|
|
484
|
+
return __generator(this, function (_b) {
|
|
485
|
+
switch (_b.label) {
|
|
486
|
+
case 0: return [4 /*yield*/, getInput(opt, defaultOpt, cmdPath)];
|
|
487
|
+
case 1:
|
|
488
|
+
bodyObject = _b.sent();
|
|
489
|
+
ajv = new ajv_1.default({ allErrors: true });
|
|
490
|
+
valid = ajv.validate(defaultOpt.opt.body, bodyObject);
|
|
491
|
+
filteredErrors = (_a = ajv === null || ajv === void 0 ? void 0 : ajv.errors) === null || _a === void 0 ? void 0 : _a.filter(function (err) { var _a; return !((_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.includes('should match exactly one schema in oneOf')); });
|
|
492
|
+
if (!valid && filteredErrors !== undefined && (filteredErrors === null || filteredErrors === void 0 ? void 0 : filteredErrors.length) > 0) {
|
|
493
|
+
throw new Error("Failed to validate input (schema mismatch):\n" + JSON.stringify(ajv.errors, null, ' '));
|
|
494
|
+
}
|
|
495
|
+
return [2 /*return*/, bodyObject];
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
}
|
package/dist/command-overview.js
CHANGED
|
@@ -1 +1,93 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.getCommandOverview = void 0;
|
|
43
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
44
|
+
var utils_1 = require("./utils");
|
|
45
|
+
function getCommandOverview(root) {
|
|
46
|
+
var _this = this;
|
|
47
|
+
return (0, utils_1.getCommand)()
|
|
48
|
+
.name('command-overview')
|
|
49
|
+
.description('Prints a tree view of all available commands')
|
|
50
|
+
.option('--verbose', 'Print command descriptions')
|
|
51
|
+
.action(function (options) { return __awaiter(_this, void 0, void 0, function () {
|
|
52
|
+
function printBranch(command, indent) {
|
|
53
|
+
var _a;
|
|
54
|
+
var getName = function (cmd, isLeaf) {
|
|
55
|
+
if (isLeaf === void 0) { isLeaf = true; }
|
|
56
|
+
return isLeaf ? chalk_1.default.bold.green(cmd.name()) : cmd.name();
|
|
57
|
+
};
|
|
58
|
+
var isTreeRoot = indent.length === 0;
|
|
59
|
+
var children = command.commands;
|
|
60
|
+
var branchHead = '';
|
|
61
|
+
var leaf = children.length === 0;
|
|
62
|
+
var isEndpointCommand = leaf || ((_a = Object.keys(command === null || command === void 0 ? void 0 : command.opts())) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
63
|
+
if (!isTreeRoot) {
|
|
64
|
+
branchHead = children && !leaf ? '┬ ' : '─ ';
|
|
65
|
+
}
|
|
66
|
+
var description = verbose && isEndpointCommand && command.description() ? ": " + command.description() : '';
|
|
67
|
+
console.log("" + indent + branchHead + getName(command, isEndpointCommand) + description);
|
|
68
|
+
var baseBranch = indent;
|
|
69
|
+
if (!isTreeRoot) {
|
|
70
|
+
var isChildOfLastBranch = indent.slice(-2) === '└─';
|
|
71
|
+
baseBranch = indent.slice(0, -2) + (isChildOfLastBranch ? ' ' : '│ ');
|
|
72
|
+
}
|
|
73
|
+
var nextBranch = baseBranch + "\u251C\u2500";
|
|
74
|
+
var lastBranch = baseBranch + "\u2514\u2500";
|
|
75
|
+
var leafLevel = children.every(function (child) { return child.commands.length === 0; });
|
|
76
|
+
if (leafLevel && !leaf && !verbose) {
|
|
77
|
+
console.log(lastBranch + " " + children.map(function (child) { return getName(child); }).join(', '));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
children.forEach(function (child, index) {
|
|
81
|
+
printBranch(child, children.length - 1 === index ? lastBranch : nextBranch);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
var verbose;
|
|
86
|
+
return __generator(this, function (_a) {
|
|
87
|
+
verbose = options.verbose;
|
|
88
|
+
printBranch(root, '');
|
|
89
|
+
return [2 /*return*/];
|
|
90
|
+
});
|
|
91
|
+
}); });
|
|
92
|
+
}
|
|
93
|
+
exports.getCommandOverview = getCommandOverview;
|